Docsity

Matrix Concepts and MATLAB Matrix Computations - Lecture Notes | BAE 200, Study notes of Agricultural engineering

Toggle sidebar
bg1
1
BAE 200
Week 5 Lecture notes:
9/23/08
Matrix Concepts and MATLAB Matrix Computations
(Engineering Analysis and MATLAB 7 - Chapter 5 p 92-100, Chapter 6 p 142-145, Chapter 9 p 247-260,
Chapter 10 276-278)
MATLAB Linear Interpolation (Engineering Analysis and MATLAB 7 - Chapter 11 p. 291-299)
Topics:
1. Matrix concepts - review some old ones and introduce some new ones
2. Introduce solving systems of linear equations using MATLAB matrix computations
3. Concept of interpolation and how it is handled in MATLAB
`
Notes:
-We have spent the first four weeks developing engineering problem solving methods, building a
foundation of programming concepts, and developing your foundation of MATLAB skills
- I have spoken often about how MATLAB is built for matrix operations but we have mostly used it in
calculations involving scalars (single value 1x1 array) and vectors (1 x n or n x 1 array), both
considered 1 dimensional arrays
Lets review what we have learned about the MATLAB matrices we have been using during our
programming thus far:
Chapters 5, 6, and 8
- User generated arrays:
o X= 4 is a scalar (1 x 1 array)
o Row vector x=[2,4,6,8] Column vector y=[1;2;3;4]
o x(1) returns?
o x = [2,4,6,8;10,12,14,16;18,20,22,24] is a 4x3 matrix
2 4 6 8
10 12 14 16
18 20 22 24
indices are
1 4 7 10
2 5 8 11
3 6 9 12
o What value is x(5) =?
o See example below
>> x=[2,4,6,8;10,12,14,16;18,20,22,24]
pf3
pf4
pf5

Partial preview of the text

Download Matrix Concepts and MATLAB Matrix Computations - Lecture Notes | BAE 200 and more Study notes Agricultural engineering in PDF only on Docsity!

BAE 200 Week 5 Lecture notes: 9/23/

Matrix Concepts and MATLAB Matrix Computations (Engineering Analysis and MATLAB 7 - Chapter 5 p 92-100, Chapter 6 p 142-145, Chapter 9 p 247-260, Chapter 10 276-278)

MATLAB Linear Interpolation (Engineering Analysis and MATLAB 7 - Chapter 11 p. 291-299)

Topics:

  1. Matrix concepts - review some old ones and introduce some new ones
  2. Introduce solving systems of linear equations using MATLAB matrix computations
  3. Concept of interpolation and how it is handled in MATLAB ` Notes:

-We have spent the first four weeks developing engineering problem solving methods, building a foundation of programming concepts, and developing your foundation of MATLAB skills

  • I have spoken often about how MATLAB is built for matrix operations but we have mostly used it in calculations involving scalars (single value 1x1 array) and vectors (1 x n or n x 1 array), both considered 1 dimensional arrays

Lets review what we have learned about the MATLAB matrices we have been using during our programming thus far: Chapters 5, 6, and 8

  • User generated arrays: o X= 4 is a scalar (1 x 1 array) o Row vector x=[2,4,6,8] Column vector y=[1;2;3;4] o x(1) returns? o x = [2,4,6,8;10,12,14,16;18,20,22,24] is a 4x3 matrix 2 4 6 8 10 12 14 16 18 20 22 24 indices are 1 4 7 10 2 5 8 11 3 6 9 12 o What value is x(5) =? o See example below

    x=[2,4,6,8;10,12,14,16;18,20,22,24]

x = 2 4 6 8 10 12 14 16 18 20 22 24

x(5) %can get a value from a particular location ans = 12 x(5)=100 % can replace a value with another number x = 2 4 6 8 10 100 14 16 18 20 22 24 o How about in an equation? y= x(5)* y = 50000 o Can use this in outputting data as well

fprintf ('this example should output x(5) %4.3f',x(5)) this example should output x(5) 100.

Time savers and commands o Evenly spaced vector time saver B=1:5 or B=[1:5] (colon separator) o If you want them spaced a certain way time = 0:2:100 gives a vector between 0 and 100 in steps of 2 o linspace - used if you want a certain amount of elements between 2 numbers

r=linspace(0,14,5) r = 0 3.5000 7.0000 10.5000 14.

This system of equations can be written as AX=B. Simplify by replacing x with x 1 , y with x 2 , and z with x (^) 3. 3 x1 + 2 x 2 - x3 = 10

  • x1 + 3 x 2 +2 x 3 = 5 x 1 - x 2 - x 3 = -

Replacing the coefficients with A and B yields:

31 1 32 2 33 3 3

21 1 22 2 23 3 2

11 1 12 2 13 3 1

A x A x A x B

A x A x A x B

A x A x A x B

can be written in matrix form as: 

3

2

1

3

2

1

31 32 33

21 22 23

11 12 13

B

B

B

x

x

x

A A A

A A A

A A A

or in matrix notation as AX=B.

Replacing the numerical coefficients yields:

3

2

1

x

x

x

A = the 3x3 matrix, X = the column vector x 1 ,x2,x3, and B = the column vector 10,5,

MATLAB can solve this for x 1 , x2 , and x 3! We will discuss this in lab!

Chapter 9 Mathematical Operations with Arrays - we need to be familiar with these

These operations between Arrays can be different than standard arithmetic operations. Scalars can be added, subtracted, multiplied and divided into matrices according to standard operations x =

2 4 6 8 10 100 14 16 18 20 22 24

5*x

ans =

10 20 30 40 50 500 70 80 90 100 110 120

5+x

ans =

7 9 11 13 15 105 19 21 23 25 27 29

5/x ??? Error using ==> mrdivide Matrix dimensions must agree.

x/

ans =

0.4000 0.8000 1.2000 1. 2.0000 20.0000 2.8000 3. 3.6000 4.0000 4.4000 4.

  • Matrix addition and subtraction: Add or subtract the corresponding elements of two arrays of identical size, e.g.,



  • Matrix addition is commutative, i.e., A+B=B+A
  • When scalar is added or subtracted to an array, it is added to or subtracted from each element in the array
  • Array multiplication : Only possible when the # of columns in the first array is equal to # of rows in second array, e.g., when A*B=AB

31 11 32 21 33 31 31 12 32 22 33 32 31 13 32 23 33 33

21 11 22 21 23 31 21 12 22 22 23 32 21 13 22 23 23 33

11 11 12 21 13 31 11 12 12 22 13 32 11 13 12 23 13 33

31 32 33

21 22 23

11 12 13

31 32 33

21 22 23

11 12 13

A B A B A B A B A B A B A B A B A B

A B A B A B A B A B A B A B A B A B

A B A B A B A B A B A B A B A B A B

B B B

B B B

B B B

A A A

A A A

A A A

  • Matrix multiplication is not commutative, i.e., AB≠BA
  • Resulting matrix has same # of rows as first matrix and same # of columns as second matrix
  • When an array is multiplied by a scalar or number (or a 1×1 matrix), each element in the array is multiplied by that quantity (multiplication of a matrix with a scalar is a commutative property)

Example of raising a matrix to a power

x =

2 4 6 8 10 100 14 16 18 20 22 24

x^

??? Error using ==> mpower Matrix must be square.

x.^

ans =

4 16 36 64 100 10000 196 256 324 400 484 576

In lab today - will discuss solving simultaneous equations using matrix operations, the SOLVE Function, and interpolation