Arrays in Matlab
Arrays in Matlab
Arrays
➢Arrays
➢Two-dimensional Arrays
➢Element-by-element Operations
➢Matrix Operations
➢Polynomial Operations Using Arrays
▪ The array is the fundamental form of Matlab,
uses to store data.
▪ Scalars: one row and one column (special case)
▪ Vectors:
✓ Row : one row and multiple columns
✓ Column: multiple rows and one column
▪ Matrices: multiple rows and multiple columns
In Matlab, a vector, or any list of numbers, can be
entered in a horizontal (row) or vertical (column)
vectors.
Ex: the data from the previous slide can be entered in
rows:[1984 1986 1988 1990 1992 1994 1996]
[127 130 136 145 158 178 211]
or in column: 1984 127
1986 130
1988 136
1990 145
1992 158
1994 178
1996 211
A vector is created by typing the elements (numbers)
Inside square brackets [ ].
To create a ROW VECTOR, type a space or a comma
between the elements inside the square brackets.
NOTE: Matlab is not “picky” about how the data
u11 u12
v11 v12
u = u21 u22 v=
u31 u32 v21 v22
f (x ) = 9 x 3 − 5 x 2 + 3x + 7 f = 9,−5,3,7
g ( x) = 6 x 2 − x + 2 g = 6,−1,2
Plotting Polynomials
Polyval(a,x): evaluates a polynomial at specified
values of its independent variable x, which can be
a matrix or a vector.
( )
Ex: f x = 9 x − 5 x + 3x + 7
3 2
3 7 − 4 12
− 5 9 10 2
A=
6 13 8 11
15 5 4 1
− 7 16 6 − 5 − 3 − 9
A= B= C=
4 9 12 − 2 6 8
1. Find A+B+C
2. Find A-B+C
3. Find A.B
4. Find D=A-B.C
5. Find D raised to the third power element-by-element
PRACTICE 4
(20 x 3
)( )
− 7 x 2 + 5 x + 10 4 x 2 + 12 x − 3 =
80 x 5 + 212 x 4 − 124 x 3 + 121 x 2 + 105 x − 30