CMPS 1371 Introduction to Computing for Engineers - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

CMPS 1371 Introduction to Computing for Engineers

Description:

The real strength of Matlab is in matrix manipulations ... To create a row vector, enclose a list of values in brackets. Create a Vector ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 17
Provided by: thaw8
Category:

less

Transcript and Presenter's Notes

Title: CMPS 1371 Introduction to Computing for Engineers


1
CMPS 1371Introduction to Computing for Engineers
  • VECTORS

2
ARRAYS
  • The real strength of Matlab is in matrix
    manipulations
  • Arrays are homogeneous collection of things.
  • All are the same
  • Are indexable

3
VECTORS
  • Our simplest array type is called a vector.
  • Simple example
  • ODDS 1 3 5 7 9 11 13 15
  • To index a vector, need to know the position
    within the vector
  • First element has position 1 (NOT ZERO!)
  • ODDS(1) 1
  • Last element either the length of the array or
    the special label end
  • ODDS(8) 15
  • ODDS(end) 15

4
Create a Vector
To create a row vector, enclose a list of values
in brackets
5
Create a Vector
You may use either a space or a comma as a
delimiter in a row vector
6
Create a Vector
Use a semicolon as a delimiter to create a new row
7
Shortcuts
  • While a complicated matrix might have to be
    entered by hand, evenly spaced matrices can be
    entered much more readily. The command 
  • b 15
  • or the command
  • b 15
  • both return a row matrix 

8
Increments
The default increment is 1, but if you want to
use a different increment put it between the
first and final values
9
To calculate spacing
  • Use linspace

number of elements in the array
Final value in the array
Initial value in the array
10
Basic Functions
  • Some basic functions
  • Consider temp 1 2 3 4 5
  • length(temp) 5
  • sum(temp) 15
  • mean(temp) 3
  • median(temp) 3

11
Calculations
  • Matrices can be used in many calculations with
    scalars
  • There is no confusion when we perform addition
    and subtraction
  • Multiplication and division are a little
    different 
  • In matrix mathematics the multiplication operator
    () has a very specific meaning regarding Matrix
    multiplication
  • We will use (.) for matrix multiplication
  • We can use () for scalar multiplication

12
Adding Vectors
13
Adding Vectors
Addition between arrays is performed on
corresponding elements
14
Multiplying Vectors
Multiplication between arrays is performed on
corresponding elements if the . operator is used
MATLAB interprets to mean matrix
multiplication. The arrays a and b are not the
correct size for matrix multiplication in this
example
15
Array Operations
  • Array multiplication .
  • Array division ./
  • Array exponentiation .

In each case the size of the arrays must match
16
Changing the Vector
  • Easy to add elements to the array
  • Temp 1 2 3 4
  • Temp(5) 8 ? Temp now has 5 elements 1, 2, 3,
    4, 8
  • Can also concatenate
  • fred 1,2,3,4 3,4,5,
  • fred fred 4 5 6 7
  • Can also remove elements by using the "Null"
    vector
  • A 1 2 3 4 5 6 7
  • A(2) now what is A
Write a Comment
User Comments (0)
About PowerShow.com