Presentation is loading. Please wait.

Presentation is loading. Please wait.

Modified Gary Larson Far Side cartoon

Similar presentations


Presentation on theme: "Modified Gary Larson Far Side cartoon"— Presentation transcript:

1 Modified Gary Larson Far Side cartoon

2 Matlab Linear Algebra Review

3 Matrices can represent sets of equations!
a11x1+a12x2+…+a1nxn=b1 a21x1+a22x2+…+a2nxn=b2 … am1x1+am2x2+…+amnxn=bm What’s the matrix representation?

4 Vectors

5 Matrices u11 u12 … u1n u21 u22 … u2n … um1 um2 … umn U = [umn] =
The general matrix consists of m rows and n columns. It is also known as an m x n (read m by n) array. Each individual number, uij, of the array is called the element Elements uij where i=j is called the principal diagonal

6 Transpose of a Matrix

7 Matrix & Vector Addition
Vector/Matrix addition is associative and commutative (A + B) + C = A + (B + C); A + B = B + A

8 Matrix and Vector Subtraction
Vector/Matrix subtraction is also associative and commutative (A - B) - C = A - (B - C); A - B = B - A

9 Matrix and Vector Scaling
ax X

10 For scalar multiplication, the size of Amn does not matter
For addition and subtraction, the size of the matrices must be the same Amn + Bmn = Cmn For scalar multiplication, the size of Amn does not matter All three of these operations do not differ from their ordinary number counterparts The operators work element-by-element through the array, aij+bij=cij

11 Vector Multiplication
The inner product or dot product v w The inner product of vector multiplication is a SCALAR

12 the same number of elements!
Inner product represents a row matrix multiplied by a column matrix. A row matrix can be multiplied by a column matrix, in that order, only if they each have the same number of elements! In MATLAB, in order to properly calculate the dot product of two vectors use >>sum(a.*b) element by element multiplication (.*) sum the results A . prior to the * or / indicates that matlab should perform the array or element by element calculation rather than linear algebra equivalent or >>a’*b

13 A column vector multiplied by a row vector.
The outer product A column vector multiplied by a row vector. In Matlab: >>a*b’ ans = The outer product of vector multiplication is a MATRIX

14 Matrix Multiplication
The inner numbers have to match Two matrices can be multiplied together if and only if the number of columns in the first equals the number of rows in the second.

15 B C A In MATLAB, the * symbol represents matrix multiplication :
>>A=B*C

16 Matrix multiplication is distributive and associative
Matrix multiplication is not commutative! C*B #taken from previous slide ans = Matrix multiplication is distributive and associative A(B+C) = AB + BC (AB)C = A(BC)

17 Revisit the vector example
>>a*b’ ans = a3x1 * b1x3 = c3x3 >>a'*b ans = 11 a1x3 * b3x1 = c1x1

18 Dot products in Matlab (using this form – built in functions - don’t have to match dimensions of vectors – can mix column and row vectors – although they have to be the same length) >> a=[1 2 3]; >> b=[4 5 6]; >> c=dot(a,b) c = 32 >> d=dot(a,b’) d =

19 Dot products using built-in function
For matrices – does dot product of columns. Essentially treating the columns like vectors. The matrices have to be the same size. >> a=[1 2;3 4] a = >> b=[5 6;7 8] b = >> dot(a,b) ans =

20 Determinant of a Matrix

21 or follow the diagonals
det (A) = a11a22a33+ a12a23a31 + a13a21a32 − a11a23a32 − a12a21a33 − a13a22a31

22 Cross-product of two vectors
The cross product a × b is defined as a vector c that is perpendicular to both a and b, with a direction given by the right-hand rule and a magnitude equal to the area of the parallelogram that the vectors span. c = a2b3-a3b2 = 2*5 – (-3)*1 = 13 a3b2-a1b *4 – 6* a1b2-a2b *1 – 2*

23 Cross products in Matlab
(using this form – built in functions - don’t have to match dimensions of vectors – can mix column and row vectors – although they have to be the same length) >> a=[1 2 3]; >> b=[4 5 6]; >> e=cross(a,b) e = >> f=cross(a,b’) f = >> g=cross(b,a) g =

24 For matrix – does cross product of columns.
(one of the dimensions has to be 3 and takes other dimension as additional vectors) >> a=[1 2;3 4;5 6] a = >> b=[7 8;9 10;11 12] b = >> cross(a,b) ans =

25 Matrix Operators + Addition - Subtraction * Multiplication / Division
\ Left division ^ Power ' Complex conjugate transpose ( ) Specify evaluation order

26 Array Operators + Addition - Subtraction
.* Element-by-element multiplication ./ Element-by-element division. A./B: divides A by B by element .\ Element-by-element left division A.\B   divides B by A by element .^ Element-by-element power .' Unconjugated array transpose the signs of imaginary numbers are not changed, unlike a regular matrix transpose

27 Operators as built-in commands plus - Plus + uplus - Unary plus + minus - Minus - uminus - Unary minus - mtimes - Matrix multiply * times - Array multiply .* mpower - Matrix power ^ power - Array power .^ mldivide - Backslash or left matrix divide \ mrdivide - Slash or right matrix divide / ldivide - Left array divide .\ rdivide - Right array divide ./ cross - cross product

28 Multiplication in Matlab
>> x=[1 2]; >> y=[3 4]; >> z=x*y’ z = 11 >> w=x.*y w = >> z=x'*y Regular matrix multiplication – in this case with vectors 1x2 * 2x1 = 1x1 => dot product Element by element multiplication Regular matrix multiplication – in this case with vectors 2x1 * 1x2 = 2x2 matrix

29 Division in Matlab In ordinary math, division (a/b) can be thought of as a*1/b or a*b-1. A unique inverse matrix of B, B-1, only potentially exists if B is square. And matrix multiplication is not communicative, unlike ordinary multiplication. There really is no such thing as matrix division in any simple sense. / : B/A is roughly the same as B*inv(A). A and B must have the same number of columns for right division.

30 \. :. If A is a square matrix, A\B is roughly the same as. inv(A)
\ : If A is a square matrix, A\B is roughly the same as inv(A)*B, except it is computed in a different way. A and B must have the same number of rows for left division. If A is an m-by-n matrix (not square) and B is a matrix of m rows, AX=B is solved by least squares.

31 The / and \ are related B/A = (A'\B')’

32 Inverse of a Matrix

33 the determinant the principal diagonal elements switch
the off diagonal elements change sign the determinant

34

35 Square matrices with inverses are said to be nonsingular
Not all square matrices have an inverse. These are said to be singular. Square matrices with determinants = 0 are also singular. Rectangular matrices are always singular.

36 Right- and Left- Inverse
If a matrix G exists such that GA = I, than G is a left-inverse of A If a matrix H exists such that AH = I, than H is a right-inverse of A Rectangular matrices may have right- or left- inverses, but they are still singular.

37 Some Special Matrices Square matrix: m (# rows) = n (# columns)
Symmetric matrix: subset of square matrices where AT = A Diagonal matrix: subset of square matrices where elements off the principal diagonal are zero, aij = 0 if i ≠ j Identity or unit matrix: special diagonal matrix where all principal diagonal elements are 1

38

39 Linear Dependence a b c 2a + 1b = c

40 Linear Independence a b c
There is no simple, linear equation that can make these vectors related.

41 Rank of a matrix

42 Acknowledgement This lecture borrows heavily from online lectures/ppt files posted by David Jacobs at Univ. of Maryland Tim Marks at UCSD Joseph Bradley at Carnegie Mellon


Download ppt "Modified Gary Larson Far Side cartoon"

Similar presentations


Ads by Google