You are on page 1of 22

Matrix Analysis February 17-19, 2014

Outline
Introduction to Matrix Analysis • Why matrices, basic definitions/terms
• Matrix multiplication
• Determinants
Larry Caretto
• Inverse of a Matrix
Mechanical Engineering 309
Numerical Analysis of • Simultaneous linear equations: matrix
from and Gaussian elimination solution
Engineering Systems
– Matrix rank and its role in determining type
February 17–19, 2014 of solutions (unique, infinite, none)
• Eigenvalues and eigenvectors
2

Why Matrices Matrix Example


• Simplified notation for general
statements about mathematical or
engineering systems • Simple linkage of two springs with
• Have multiple components that are spring constant k and displacements uk
interrelated at individual points
– Elements in a machine structure • Individual loads, Pk, related to individual
– Springs, masses and dampers in a displacements, uk, by matrix equation
vibrating system shown below.
• Matrix notation provides general 𝑃1 𝑘1 −𝑘1 0 𝑢1
P= 𝑃2 = −𝑘1 𝑘1 + 𝑘2 −𝑘2 𝑢2 = 𝑲𝑼
relationships among components 𝑃3 0 −𝑘2 𝑘2 𝑢3
3 4

Matrix Basics Row and Column Matrices


 a11 a12 a13   a1m  • Matrices with only one row or only one
• Array of
a a a23   a2 m  column are called row or column matrices
 21 22  numbers with
a31 a32 a33   a3 m  (sometimes called row or column vectors)
A n rows and m
 – The row number 1 is usually
       columns dropped in row matrices as is  c11   c1 
       • Components c   c 
  the column number 1 in  21   2 
  anm 
 a n1 a n 2 c  c31   c3 
an 3 are a(row)(column) column matrices
 
• Size of matrix (n x m) or (n by m) is r  r11 r12 r13   r1m     
   
number of rows and columns  r1 r2 r3   rm  cn1  cn 

5 6

ME 309 – Numerical Analysis of Engineering Systems 1


Matrix Analysis February 17-19, 2014

More Matrix Basics Diagonal Matrix


• Two matrices are equal (e.g., A = B) a1 0 0   0  • The diagonal matrix
– If both A and B have the same size (rows 0 a 0   0 A is a square
and columns)  2 
0 0 a3   0 matrix with nonzero
– If each component of A is the same as the A  components only
corresponding component of B (aij = bij for     
     on the principal
all i and j)
  diagonal
• A square matrix has the same number 0 0 0   an 
of rows and columns • Components of A are 1 i  j
• A diagonal matrix, D, has all zeros aidij, where dij is the d ij  
except for the principal diagonal Kroenecker delta 0 i  j
7 8

Matrix Operations Null (0) and Unit (I) Matrices


• Can add or subtract matrices if they are • For any matrix, A, A + 0 = 0 + A = A;
the same size IA = AI = A and 0 A = A 0 = 0
– C = A  B only valid if A, B, and C have • The unit (or identity) matrix is a square
the same size (rows and columns) matrix; the null matrix, which need not
– Components of C, cij = aij  bij be square, is sometimes written 0(nxm)
• Multiplication by a scalar: C = xA 0 0 0   0 1 0 0   0
0   0 0   0
– C and A have the same size (rows and  0 0  1 0
0 0 0 0 0 0 1   0
columns) 0  I 
         
– Components of C, cij = xaij          
   
– For scalar division, C = A/x, cij = aij/x 0 0 0   0 0 0 0   1

9 10

Transpose of a Matrix Matrix Multiplication Preview


• Transpose of A denoted as AT • Not an intuitive operation. Look at two
• Reverse rows and columns; for B = AT coordinate transformations as example
– bij = aji y1  a11x1  a12 x2 z1  b11 y1  b12 y2
– If A is (n x m), B = AT is (m by n) y2  a21x1  a22 x2 z2  b21 y1  b22 y2
• In MATLAB the apostrophe is used to construct
the transpose: B = A’ • Substitute equations for y in terms of x
 3 14 
into equations for z1 and z2
 3 12  6 z1  b11[a11x1  a12 x2 ]  b12[a21x1  a22 x2 ]
A  AT   12  2
14  2 0   
 6 0  z 2  b21[a11x1  a12 x2 ]  b22[a21x1  a22 x2 ]
11 12

ME 309 – Numerical Analysis of Engineering Systems 2


Matrix Analysis February 17-19, 2014

Matrix Multiplication Preview II Matrix Multiplication Preview III


• Rearrange last set of equations to get • Coefficients as matrix components
direct transformation from x to z a a  b b  c c 
A   11 12  B   11 12  C   11 12 
z1  [b11a11  b12a21]x1  [b11a12  b12a22 ]x2  c11x1  c12 x2 a21 a22  b21 b22  c21 c22 
z 2  [b21a11  b22a21]x1  [b21a12  b22a22 ]x2  c21x1  c22 x2
c c  b a  b a b a b a 
c11  [b11a11  b12a21] c12  [b11a12  b12a22 ] C   11 12    11 11 12 21 11 12 12 22 
c21 c22  b21a11  b22a21 b21a12  b22a22 
c21  [b21a11  b22a21] c22  [b21a12  b22a22 ] 2

2 C = AB if cij   bik akj (i  1,2; j  1,2)


cij   bik akj (i  1,2; j  1,2) k 1

k 1 • Generalize this to any matrix size


13 14

Multiplying Matrices General Matrix Multiplication


• For general matrix multiplication, C = AB • For matrix multiplication, C = AB
p p
– A has n rows and p columns cij   aik bkj – A has n rows and p columns cij   aik bkj
– B has p rows and m columns k 1 – B has p rows and m columns k 1
– C has n rows and m columns (i  1, n; j  1, m) – C has n rows and m columns (i  1, n; j  1, m)
– A is left; B is right; C is product – A is left; B is right; C is product
• For C = AB, we get cij by adding prod- (AB)ij is
• Example 3 4 product of row i
ucts of terms in row i of A (left matrix)  3 0  6
A  B  1 2 of A times
by terms in column j of B (right matrix) 4  2 0   
6 1
column j of B
• cij = ai1b1j + ai2b2j + ai3b3j + ai4b4j + …  3(3)  0(1)  6(6) 3( 4)  0( 2)  6(1)    27 6 
• In general, AB ≠ BA AB    
4(3)  2(1)  0(6) 4( 4)  2( 2)  0(1)  10 12

15 16

Matrix Multiplication Exercise Matrix Multiplication Exercise II


• Consider the following matrices • What is the size of C = AB?
1 2 3 0 2  2 0
1 2 3 0 2  2 0
A  0  1 4   1 3 1 0 
  B
  A  0  1 4  B  1 3 1 0 
   
1 1 0 2 1  3 1 1 1 0 2 1  3 1
• Can you find AB, BA or both?
• We can find AB, because A has three • C = AB has three rows (like A) and four
columns and B has three rows columns (like B)
• We cannot find BA because B has four • What is c11?
columns and A has three rows
• Next chart starts the process of finding all • c11 = (1)(0) + (2)(1) + (3)(2) = 8
components of AB
17 18

ME 309 – Numerical Analysis of Engineering Systems 3


Matrix Analysis February 17-19, 2014

Matrix Multiplication Exercise III Matrix Multiplication Exercise IV


• Find c11, c12, c13, and c14 in C = AB • Find c21, c22, c23, and c24 in C = AB
1 2 3 0 2  2 0 1 2 3 0 2  2 0
A  0  1 4  B  1 3 1 0  A  0  1 4  B  1 3 1 0 
       
1 1 0 2 1  3 1 1 1 0 2 1  3 1
• c11 = (1)(0) + (2)(1) + (3)(2) = 8 • c21 = (0)(0) + (-1)(1) + (4)(2) = 7
• c12 = (1)(2) + (2)(3) + (3)(1) = 11 • c22 = (0)(2) + (-1)(3) + (4)(1) = 1
• c13 = (1)(-2) + (2)(1)
8 11 + 9(3)(-3)
3 = -9 • c23 = (0)(-2) + (-1)(1) + (4)(-3) = -13
  8 11  9 3
• 
c14 = (1)(0) +C (2)(0) + (3)(1)  =3 • C +7(-1)(0)
c24 = (0)(0) 4
+ (4)(1)
1  13 =4
   
19   20

Matrix Multiplication Exercise V Matrix Multiplication Results


• Find c31, c32, c33, and c34 in C = AB • Solution for matrix product C = AB
1 2 3 0 2  2 0 1 2 3 0 2  2 0
A  0  1 4  B  1 3 1 0  A  0  1 4  B  1 3 1 0 
       
1 1 0 2 1  3 1 1 1 0 2 1  3 1
• c31 = (1)(0) + (1)(1) + (0)(2) = 1
8 11  9 3

C  7 1  13 4
c32 = (1)(2) + (1)(3) + (0)(1) = 5
 
• c33 = (1)(-2) + (1)(1) + (0)(-3) = -1 1 5  1 0
8 11  9 3
• c34 = (1)(0)C + (1)(0) 13 4= 0
7 1 +(0)(1)
 
1 5 1 0 21 22

MATLAB/Excel Matrices Determinants


• Have seen term-by-term operations on • Looks like a matrix but isn’t a matrix
arrays, A+B, A-B, A.*B, A./B and A.^n • A square array of numbers with a rule
• Matrix operations are given by following: for computing a single value for the
array
A+B, A-B, A*B, A/B, A\B and A^n
1 3 1 9 Example at  a11 a12 a13  a11 a12 a13
• MATLAB 𝑨 = 𝑨. ^𝟐 =
Det a21 a22 a23   a21 a22 a23
2 4 4 16 right shows
calculation of
𝟐 1 3 1 3 7 15 a31 a32 a33  a31 a32 a33
• A^2: 𝑨 = = Det(A), the
2 4 2 4 10 22 determinant of a11a22a33  a21a32a13  a31a12a23
• Excel has mmult array function to 3 x 3 matrix A   a a a  a a a  a a a
11 32 23 21 12 33 31 22 13
multiply two arrays
23 24

ME 309 – Numerical Analysis of Engineering Systems 4


Matrix Analysis February 17-19, 2014

More Determinants General Rule for Determinants


• Useful in obtaining algebraic • Any size determinant can be evaluated
expressions for matrix operations, but by any of the following equations
not useful for numerical computation n n n n

– Equation for 2 by 2 determinant Det A   (1)i  j aij M ij  (1)i  j aij M ij   aij Aij  aij Aij
i 1 j 1 i 1 j 1
a a  a a
Det A  Det  11 12   11 12  a11a22  a21a12
a21 a22  a21 a22 • Can pick any row or any column
• Choose row or column with most zeros to
• An n x n determinant has n2 Minors, Mij, simplify calculations
obtained by deleting row i and column j
• Can apply equation recursively; evaluate a 5
• Cofactors, Aij = (-1)i+jMij used in general x 5 determinant as a sum of 4 x 4 deter-
expressions for determinants minants then get 4 x 4’s in terms of 3 x 3’s
25 26

Determinant Behavior Determinant Behavior II


• A determinant is zero if any row or any • If one row (or one column) of a
column contains all zeros. determinant is replaced by a linear
• If one row or one column of a combination of that row (or column) with
determinant is multiplied by a constant, another row (or column), the value of
k, the value of the determinant is the determinant is not changed.
multiplied by the same constant. • If two rows (or two columns) of a
– Note the implication for matrices: if a matrix determinant are linearly dependent the
is multiplied by a constant, k, then each value of the determinant is zero.
matrix element is multiplied by k. If A is an
n x n matrix, Det(kA) = knDet(A).
27 28

Determinant Behavior III Inverse of a Matrix


• The determinant of the product of two • For a square matrix, A, an inverse matrix,
matrices, A and B is the product of the A-1 may exist such that AA-1 = A-1A = I
determinants of the individual matrices: • For the algebraic equation ax = b, x = a-1b
Det(AB) = Det(A) Det(B). • For the matrix equation Ax = b, x = A-1b
• The determinant of transposed matrix is the • Just as x = a-1b is not valid if a = 0, x =
A-1b is not valid if A-1 does not exist
same as the determinant of the original – A-1 does not exist if DetA = 0
matrix: Det(AT) = Det(A). • The inverse is an important concept in
• MATLAB: det(A) gives Det(A) analysis of linear systems, but is not used
• Excel: mdeterm; video for all Excel matrix in computational work
– http://www.youtube.com/watch?v=gY81Jg7jyc4
29 30

ME 309 – Numerical Analysis of Engineering Systems 5


Matrix Analysis February 17-19, 2014

Formula for Inverse of a Matrix Inverse of 2 x 2 Matrix


• Find the components of B = A-1, bij, from Aji M ji
If B  A 1 , bij   ( 1)i  j
determinant of A and its cofactors Det ( A) Det ( A)
Aji M ji
If B  A 1 , bij   ( 1)i  j b11  ( 1)11
M 11

a22
b12  ( 1)1 2
M 21

a12
Det ( A) Det ( A) Det ( A ) Det ( A ) Det ( A ) Det ( A )
• Use to get algebraic equations for b21  ( 1) 2 1
M 12

a21
b22  ( 1) 2  2
M 22

a11
Det ( A ) Det ( A ) Det ( A ) Det ( A )
components of inverse matrix
• Matrix computations, if necessary, obtain a a  1  a22  a12 
A   11 12  A 1 
components by alternative numerical
 21 22 
a a a11a22  a21a12  a21 a11 
algorithms
31 32

Inverse of 3 x 3 Matrix MATLAB/Excel Inverse


1
Apply BA , 1
• MATLAB: use B = inv(A) to get B = A-1
 a11 a12 a13  • MATLAB can use C=B/A to get C = A-1B
M ji a a  
bij  ( 1)i  j a
 21 22 23  • Excel function minverse computes inverse
Det ( A ) a31 a32 a33  – Select empty cell area same size as matrix
– Enter formula =minverse(<matrix cells>)
(a22a33  a32a23 ) ( a32a13  a33a12 ) (a12a23  a22a13 )
– Press control+shift+enter
 (a a  a a ) (a a  a a ) (a a  a a ) 
 31 23 33 21 11 33 31 13 21 13 11 23 

(a21a32  a31a22 ) (a31a12  a11a32 ) ( a11a22  a21a12 ) 


– Original matrix in cells A1:B2
 a11a22a33  a21a32a13  a31a12a23 
  a a a  a a a  a a a  – Array formula =minverse(A1:B2) in cells C1:D2
 11 32 23 21 12 33 31 22 13  – Array formula =mmult(A1:B2,C1:D2) in cells E1:F2
33 34

Simultaneous Equation Basics Simultaneous Equations


• A set of simultaneous linear algebraic
• The second column is an equivalent set
equations may have
– A single (unique) solution
of equations that is a linear combination
– No solution
of the equations in the first column
– An infinite number of solutions 3x1  5 x2  13 3x1  5 x2  13 x1  1
• A linear combination of any two 6 x1  11x2  28 x2  2 x2  2
equations can replace one of the 3x1  5 x2  13 x1  a (any a)
3x1  5 x2  13
13  3a
equations and not change the solution 6 x1  10 x2  26 00 x2 
5
Eqn I 3 x1  5 x2  13 6 x1  11x2  28 (Eqn II) –
3x1  5 x2  13 3x1  5 x2  13
Eqn II 6 x1  11x2  28  23x1  5 x2  13 2 * (Eqn I) 6 x1  10 x2  25 0  1
No solution

x2  2 35 36

ME 309 – Numerical Analysis of Engineering Systems 6


Matrix Analysis February 17-19, 2014

Getting to a Matrix Form Standard Form


• Example of 3 equations (3 unknowns)
3x + 7y – 3z = 8 a11x1 + a12x2 + a13x3 +...+ a1N-1xN-1 + a1NxN = b1
2x – 4y + z = -3 a21x1 + a22x2 + a23x3 +...+ a2N-1xN-1 + a2NxN = b2
8x + 6y – 2z = 14 a31x1 + a32x2 + a33x3 +...+ a3N-1xN-1 + a3NxN = b3
• How can we develop a general notation ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
for N equations in N unknowns? aN-1,1x1 + aN-1,2x2 + .. ... ... ... ...+ aN-1,NxN = bN-1
– Call variables x1, x2, x3 etc. aN1x1 + aN2x2 + aN3x3 +... ... ... ... ..+ aNNxN = bN
– Call right hand side b1, b2, b3, etc. • Usual subscripts on a are arow,column
– Call top row coefficients a11, a12, a13, etc.
• Row is equation and x column is unknown
∙ Coefficient of xj in equation i is aij
• N can be any number
37 38

Compact Standard Forms Example in Standard Form


N
• Previous example of 3 equations (N = 3)
• Ax = b a x
j 1
ij j  bi i  1,, N
3x + 7y – 3z = 8
• Equations defined by data: N, aij, and bi 2x – 4y + z = -3
• Summation is same as matrix 8x + 6y – 2z = 14
multiplication formula • In standard form:
• aij coefficients are a matrix, A – x is x1, y is x2, and z is x3
• Right-hand side, b, and unknowns, x, – a11 = 3, a12 = 7, a13 = -3, b1, = 8
are column vectors – a21 = 2, a22 = -4, a23 = 1, b2, = -3
– a31 = 8, a32 = 6, a33 = -2, b3, = 14
39 40

Example in Standard Form Example in Standard Form


• Multiply A and x as shown below
• Previous 3x + 7y – 3z = 8 3 7 −3 x1 3x1 + 7x2 − 3x3 8
example of N 2x – 4y + z = -3 2 −4 1 x2 = 2x1 − 4x2 + 1x3 = −3
= 3 equations 8x + 6y – 2z = 14 8 6 −2 x3 8x1 + 6x2 − 2x3 4
• Final equal sign for two (3x1) matrices
3 7  3  x1   8  gives original form of three simultaneous
2  4 1   x2    3
equations
• As Ax = b 3x + 7y – 3z = 8

8 6  2  x3   14  2x – 4y + z = -3
8x + 6y – 2z = 14
41 42

ME 309 – Numerical Analysis of Engineering Systems 7


Matrix Analysis February 17-19, 2014

Solve Ax = b in MATLAB/Excel Solving Ax = b


• MATLAB could use x = inv(A) * b
• Know A (all the aij) and b (all bi)
– Preferred approach is x = b\A which is
faster and more accurate for solving Ax=b • Want x (all the unknowns xi)
• Excel: Select column for x solution then  a11 a12 a13   a1n   x1   b1 
enter array formula:
a a a23   a2 n   x2  b2 
 21 22    
– mmult(minverse(<A cells>), <b cells>) a31 a32 a33   a3n   x3  b3 
Array formula    
in f2:f4 is:        
=mmult(a2:c4,        
Array formula in e2:e4 is: e2:e4)-d2:d4     
=mmult(minverse(a2:c4),d2:d4)  an1 an 2 an 3   ann   xn  bn 
43 44

General System for Ax = b n equations and m unknowns?


• How can this be? We expect m = n
(n x m) (m x 1) (n x 1) • First we have to see if the n equations
 x1  are really independent equations
 a11 a12 a13   a1m     b1 
a x2 • Systems for m > n have an infinite
 21 a22 a23   a2 m    b2 
 x3  number of solutions
 a31 a32 a33   a3m    b3 
     • Systems for n > m can be solved in a
         
least squares sense
         
     – Provide solution that has least error in
 an1 an 2 an 3   anm     bn  𝑛
𝑏𝑖 − 𝑚 2
solution: minimize 𝑖=1 𝑗=1 𝐴𝑖𝑗 𝑥𝑗
 xm 
45 46

Gauss Elimination Upper Triangular Form (UTF)


• Practical tool for obtaining solutions • Convert original set of equations to UTF
• Analytical tool for determining linear
11 12 13   1n 1 1n   x1   1 
dependence or independence 0 
  23    2 n 1  2 n   x2    2 
• Basic idea is to manipulate the 22

equations (or data) to make them easier 0 0  33    3n 1  3n   x3    3 


    
to solve without changing the results          
• Systematically create zeros in lower left           
    
part of the equations (or data)
0 0 0    n 1n 1  n 1n   xn 1    n 1 
0   0  nn   xn    n 
 0 0
47 48

ME 309 – Numerical Analysis of Engineering Systems 8


Matrix Analysis February 17-19, 2014

Gauss Elimination III Gauss Elimination Algorithm


• Upper triangular form on previous slide • How do we get the upper triangular form?
is easily solved by back substitution • Work on augmented matrix
• xn = n/nn
• xn-1= (n-1 – n-1 nxn)/n-1 n-1, et cetera  a11 a12 a13   a1m b1 
a   a2 m b2 
• General equation for back substitution  21 a22 a23
n a a a33   a3m b3 
i  
j i 1
ij xj [ A, b]   31 32
      

xi  i  n, n  1, n  2, ,1  
 ii     
Convention: If lower index is  
greater than upper index in S an1 an 2 an 3   anm bn 
operator, do not execute sum 49 50

Gauss Elimination Algorithm II General Gauss Elimination


• Use each row from row 1 to row n-1 as
• Repeatedly replace rows by linear the “pivot” row
combination of two rows that produces a – Diagonal element on pivot row is apivot,pivot
zero in a desired row/column combination – For each row (row r) below the pivot row
• First step: make all of column 1 below row • Multiply that row by arow,pivot/apivot,pivot
1 zero (sets all ar1 = 0 except a11) • Subtract result from row r to make arow,pivot = 0
• Operation requires subtraction for each column
• Second step: make all of column 2 below of A right of pivot column and for b
row 2 zero (sets all ar2 = 0 for r > 2) – Repeat for each row below pivot row
• Continue this kind of step for all rows
• Repeat for rows 1 to n-1 as pivot rows
except the last row
– Row being subtracted is called “pivot row” • Replace existing array with results of
new operations
51 52

General Gauss Elimination II Gauss Pseudocode


• Operations with row 2 as pivot row For pivot  1 to n  1
• Replace RowR by {RowR – (aR2/a22)Row2}  For row  pivot  1 to n 
a11 a12 a13   a1m b1   
0    For column  pivot  1 to n  
a22 a23   a2 m b2   
   
a
  arow,column  arow,column  row, pivot a pivot ,column
0 a
a32  32 a22
a
a33  32 a23   a3m 
a32
a2 m b3 
a32 
 a  
 b2    pivot , pivot  
a22 a22 a22 a22   
 a a a    
0 a
a42  42 a22 a43  42 a23  a4 m  42 a2 m b4  42 b2    arow, pivot 
 a22 a22 a22 a22   brow  brow  b pivot 
         a pivot , pivot 
 an 2 an 2 an 2 an 2    
0 an 2  a22 an 3  a23   anm  b
a2 m n  b2   
 a22 a22 a22 a22 
Operations on brow are the same
arow, pivot
arow,column  arow,column  a pivot ,column 53 as operations would be on arow,n+1 54
a pivot , pivot

ME 309 – Numerical Analysis of Engineering Systems 9


Matrix Analysis February 17-19, 2014

Solution Details More Details


• Solve the set 2 x1  4 x2  26 x3  34 (i ) • Result from 2 x1  4 x2  26 x3  34
of equations  3x1  2 x2  9 x3  13 (ii ) first set of 0 x1  4 x2  30 x3  38
on the right operations 0 x1  17 x2  99 x3  133
7 x1  3x2  8 x3  14 (iii )
• Subtract –3/2 times (i) from equation (ii) • Subtract   17 
x2 17  
 
(4)  x3 99 
 4  
and 7/2 times (i) from (iii) 17/(-4) times
 17     17  
  3    3    3    3  (ii) from (iii)  (30)  133   (38)
4   4 
 3   2 2 x1  2   2 (4) x2  9   2 (26) x3  13   2 (34)
               
2 x1  4 x2  26 x3  34
 7   7   7   
• Final upper- 0 x1  4 x2  30 x3  38
7
7   2 2 x1  3   2 (4) x2  8   2 (26) x3  14   2 (34) triangular form
                0 x1  0 x2 
57
x3  
57
2 2
Unnecessary operations 55 56

Back Substitution Do we have a solution to Ax = b?


2 x1  4 x2  26 x3  34
• Final upper- 0 x1  4 x2  30 x3  38 • Answer to question based on the rank
triangular form 57 57
which is defined as the number of
0 x1  0 x2  x3   linearly independent rows or columns
2 2
• Use Gauss elimination to determine rank
• We see that x3 = 1 and back substitution
– Use Gauss elimination to convert matrix to
gives x2 and x1 as follows upper-triangular form
 4 x2  30 x3  38 2 x1  4 x2  26 x3  34
– In this form, rank is number of rows with
 38  30( x3 )  38  30(1)  34  4 x2  26 x3
x2   x1  non-zero coefficients
4 4 2
– This is sometimes called row-echelon form
x2  2  34  4(2)  26(1)
x1  0 • MATLAB has function rank(matrix)
2
57 58

What is a row-echelon form? What is the rank of each matrix?


• Apply Gauss elimination to get
– All zeros below row one in column one 6 0 2 0 0 0 1 6 6 0 2 0 0 0
– All zeros below row two in column two 0 1 7 8 6 2 8 4 0 1 7 8 6 2
 
– Keep this up until you get to the final row or 0
0 0 2 0 3 5 8 0 0 3 4 0 0
until there are no more rows with nonzeros    
• Count number of rows that are not all 0 0 0 4 1 0 7 3 0 0 0 9 1 2
zeros; this is the rank 0 0 0 0 6 0 3 5 0 0 0 0 0 0
   
• This is way to determine linear 0 0 0 0 0 0 2 1  0 0 0 0 0 0
independence of a set of vectors
6 4

59 60

ME 309 – Numerical Analysis of Engineering Systems 10


Matrix Analysis February 17-19, 2014

Finding Rank Solutions to Ax = b


 12  • For a system of n unknowns
• What is rank of matrix, 1
A?  6 72  • If rank A = rank [A b] = n there is a
A  unique solution
• What is maximum pos-  13  156 
sible value for rank? 2   • If rank A = rank [A b] < n there are an
 7 84  infinite number of solutions
• Lower right matrix is
1  12 • If rank A  rank [A b] there are no
result of applying Gauss 0 0 
elimination to A   solutions
• What is its rank? 0 0 
 
• Rank A = 1 0 0 
61 62

Three Examples First Example Rank


Original Equations Triangularized Set Solutions
x1  4 x2  26 x3  2 x1  4 x2  26 x3  2 x1  0 1  4  26 1  4  26 2 
2 x2  9 x3  5 2 x2  9 x3  5 x 2  7
Original A  0 2 9  A b  0 2 9  5 
7 x1  3x2  8 x3  13 50.5 x3  50.5 x3  1 7 3 8  7 3 8  13

x1  4 x2  26 x3  2 x1  4 x2  26 x3  2 x1  8  8 Row- 1  4  26 1  4  26 2 
2 x2  9 x3  5 2 x2  9 x3  5 x2  2.5  4.5 echelon A  0 2 9  A b  0 2 9  5 
 2 x1  10 x2  61x3  9 00 x3   form 0 0 50.5 0 0 50.5 50.5
x1  4 x2  26 x3  2 x1  4 x2  26 x3  2
No Here we see that rank A = rank [A b] =
2 x2  9 x3  5 2 x2  9 x3  5 number of unknowns = 3 so we have a
solution
 2 x1  10 x2  61x3  8 0 1 unique solution
63 64

Second Example Rank Third Example Rank


 1  4  26 1  4  26 2 
 1  4  26  1  4  26 2 
Original A   0 9  A b   0 9  5
A   0 9  A b   0 2 9  5 2 2
2 Original
 2 10 61   2 10 61  9
 2 10 61   2 10 61  8

Row- 1  4  26 1  4  26 2 
Row- 1  4  26 1  4  26 2  A  0 2 9 
echelon A b  0 9  5
A  0 2 9  A b  0 2 9  5
2
echelon 0 0 0 
0 0 0  0 0 0 
form 0 0 0 1 
form 0

rank A = rank [A b] = 2 which is less Here, rank A = 2  rank [A b] = 3;


than the number of unknowns (3) so we therefore we have no solutions
have an infinite number of solutions
65 66

ME 309 – Numerical Analysis of Engineering Systems 11


Matrix Analysis February 17-19, 2014

Homogenous Equations Homogenous Equation Example


• If b = 0, i.e., each bi = 0, we a11 = -1 A matrix
automatically have rank A = rank[A b] Equations
 x1  4 x2  3x3  0  1  4 3 
so we have a solution  4 x1  11x2  6 x3  0 A   4 11  6
• If this rank equals the number of x1  8 x2  5 x3  0  1  8 5 
unknowns, we have a unique solution,
x=0 Original [A b] matrix Row-echelon form
 1  4 3 0  1  4 3 0
• If this rank is less than the number of [ A b]   4 11  6 0 [ A b]   0 27  18 0
unknowns we have an infinite number of
 1  8 5 0  0 0 0 0
solutions
Rank A = rank [A b] = 2 < unknowns = 3 so
67 there are infinite solutions 68

Homogenous Equation Example II Rank and Determinants


Equations a11 = +1 A matrix • Determinant rank, like matrix rank, is
x1  4 x2  3x3  0  1 4 3  the number of linearly independent
 4 x1  11x2  6 x3  0 A   4 11  6 rows or columns.
x1  8 x2  5 x3  0  1  8 5  • Two equivalent statements: a
Original [A b] matrix Row-echelon form determinant is zero if
 1 4 3 0 4
1 3 0 – its rows are linearly dependent
[ A b]   4 11  6 0 [ A b]   0
5 6 0 – the size of a determinant is larger than
 
 1  8 5 0
 0
0 2.8 0 its rank

Rank A = rank [A b] = unknowns = 3 so
there is a unique solution (x = 0) 69 70

Practical Determinant Evaluation Upper Triangular Determinant


• Use Gauss elimination and find the
product of the elements on the diagonal a11 a12 a13 a14 a15
a22 a23 a24 a25
– A determinant does not change if one row 0 a22 a23 a24 a25
0 a33 a34 a35
is replaced by a linear combination of that 0 0 a33 a34 a35  (1)11 a11
row with another row 0 0 a44 a45
– Gauss elimination converts a determinant 0 0 0 a44 a45
0 0 0 a55
into upper-triangular form without changing 0 0 0 0 a55
its value
a33 a34 a35
– The determinant of an upper-triangular a a45
array is the product of the components on  a11 (1) 2 2 a22 0 a44 a45  a11a22 (1) 33 a33 44
0 a55
the principal diagonal 0 0 a55
5
71  a11a22 a33 a44 a55   akk 72

k 1

ME 309 – Numerical Analysis of Engineering Systems 12


Matrix Analysis February 17-19, 2014

Determinant Sign Homogenous Infinite Solutions


• Gauss elimination uses row swapping to
Example a11 = –1 A matrix
reduce round-off error
 x1  4 x2  3x3  0  1  4 3 
• If two rows in a determinant are swap-  4 x1  11x2  6 x3  0 A   4 11  6
ped, the determinant sign changes x1  8 x2  5 x3  0
𝟏 𝟐  1  8 5 
𝑫𝒆𝒕 = 𝟏 𝟒 − 𝟑 𝟐 = −𝟐
𝟑 𝟒 Row-echelon form ~
𝟑 𝟒 Det A  Det A  (1)(11)(5) 
𝑫𝒆𝒕 = 𝟑 𝟐 − 𝟏 𝟒 =𝟐
𝟏 𝟐  1  4 3
(4)(8)(3)  (1)(4)(6)
• In Gauss elimination keep a count of the A   0 27  18
~
 (1)(11)(3)  (4)(4)(5)  (1)(8)(6)
row swaps, nSwaps; find determinant  0 0 0
 55  96  24  33  80  48  0
from diagonalized array by the formula
𝑁 Det A = 0 => solution of x  0 may exist
𝑛𝑆𝑤𝑎𝑝𝑠
−1 𝛼𝑘𝑘 73 74
𝑘=1

Homogenous Infinite Solutions Cramer’s Rule


Example a11 = +1 A matrix
 1 4 3  • You may like to use this for small
x1  4 x2  3x3  0
 4 x1  11x2  6 x3  0 A   4 11  6 systems of equations
x1  8 x2  5 x3  0  1  8 5 
Det A  (1)(11)(5)  b1 a12 a13 a11 b1 a13 a11 a12 b1
Row-echelon form (4)(8)(3)  (1)(4)(6) b2 a22 a23 a21 b2 a23 a21 a22 b2
1  4 3   (1)(11)(3)  (4)(4)(5)  (1)(8)(6) b a32 a33 a b3 a33 a a32 b3
x1  3 x2  31 x3  31
A  0  5 6 
~
 55  96  24  33  80  48  14 a11 a12 a13 a11 a12 a13 a11 a12 a13
0 0  2.8 a21 a22 a23 a21 a22 a23 a21 a22 a23
~
Det A  (1)(5)(2.8)  14 Det A  0 and b = 0 a31 a32 a33 a31 a32 a33 a31 a32 a33
means x = 0
75 76

Rank and Inverses Rank and Inverses II


• Finding A-1
for an n x n matrix requires
• Recall the general result for the elements,
the solution of Ax = b n times, where b
bij, of B = A-1
is one column of the unit matrix
• bij = Aji/Det(A), where Aij is the cofactor of aij
• We cannot solve this equation unless
• We see that bij is not defined if Det A = 0
rank A = n
• A-1 does not exist if Det A = 0
• An n x n square matrix A will not have
• Det A = 0 for an n x n determinant shows
an inverse unless its rank equals its size that Rank A < n
• An alternative statement is that A will • Det A  0 and rank A = n: two equivalent
not have an inverse if Det(A) = 0 conditions for A(n x n) to have an inverse
77 78

ME 309 – Numerical Analysis of Engineering Systems 13


Matrix Analysis February 17-19, 2014

Why Eigenvalues/Eigenvectors Eigenvalues and Eigenvectors


• In electrical and mechanical networks, • Basic definition (A square): Ax = lx
provides fundamental frequencies • x is eigenvector, l is eigenvalue
• Shows coordinate transformations • Basic idea is that eigenvector is special
appropriate for physical problems vector of matrix A; multiplication of x by
• Provides way to express network A produces x multiplied by a constant
problem as diagonal matrix • Ax = lx => Ax – lx = [A – Il]x = 0
• Transformations based on eigenvectors • Homogenous equations; requires Det [A
used in some solutions of Ax = b – Il] = 0 for solution other than x = 0

79 80

Det[A – Il] = 0 Two-by-two Matrix Eigenvalues


a11  l a12 a13   a1n  • Quadratic a11  l a12
 a a22  l a23   a2 n  equation with 

 a
21

a32 a33  l   a3 n 

two roots for
a21 a22  l
Det[ A  Il ]  Det  31 0
       eigenvalues (a11  l)(a22  l)  a21a12 
      

 a n1 an 2 an 3

  ann  l  l2  (a11  a22 )l  a11a22  a21a12  0
• Eigenvalue solutions
• Det[A – Il] = 0 produces an nth order
equation that has n roots for l. May (a11  a22 )  (a11  a22 )2  4(a11a22  a21a12 )
have duplicate roots for eigenvalues. l
81
2 Det A 82

Two-by-two Matrix Eigenvalues Sum and Product


• Write (a11  a22 )2  4Det A as • The results on the previous slide apply
• Add the two solutions to get to all matrices
• The sum of the eigenvalues is the sum
(a11  a22 )  (a  a ) 
l1  l2   11 22  a11  a22 of the diagonal elements of the matrix,
2 2 called the trace of the matrix
• Multiply the two solutions to get
• The product of the eigenvalues is the
 (a  a ) 
l1l 2   11 22
 (a11  a22 ) 

 (a11  a22 ) 2 

 
2
determinant of the matrix
2  2  4
   n n n

(a  a ) 2  (a11  a22 ) 2  4 Det A


 11 22  Det A
 l  a
i 1
i
i 1
ii  Trace A l
i 1
i  Det A
4
83 84

ME 309 – Numerical Analysis of Engineering Systems 14


Matrix Analysis February 17-19, 2014

Two-by-two Matrix Eigenvectors Two-by-two Eigenvectors II


• Two eigenvectors: x(1) = [x(1)1 x(1)2]T and • Eigenvector equations are homogen-
x(2) = [x(2)1 x(2)2]T (x(j) = [x(j)1 x(j)2]T) eous, so eigenvectors are determined
only within a multiplicative constant
• Substitute each eigenvalue solution, lj,
into (A – Il)x = 0 to find all x(j) components • Pick x(j)1 =  (a11  l j ) x( j )1  a12 x( j ) 2  0
(a11  l j ) x( j )1  a12 x( j ) 2  0 (arbitrary) a21x( j )1  (a22  l j ) x( j ) 2  0
a21x( j )1  (a22  l j ) x( j ) 2  0 (l j  a11) a21
x( j )1   x( j ) 2   
Notation: yi is component i of vector y; z(k) a12 (l j  a22 )
is one of a vector set with components z(k)i
85 86

How Many Eigenvalues? Diagonalize a Matrix


• An n x n matrix has k  n distinct • For an n x n matrix it is possible to
eigenvalues create a matrix, X, where each column
• Algebraic multiplicity of an eigenvalue, is one eigenvector
Ml, is the number of roots of Det[A – Il] • One can then show that X-1AX = L,
= 0 that have the same root, l where L is a diagonal matrix whose
• Geometric multiplicity, ml, of eigenvalue components are the eigenvalues
is number of linearly independent – Next assignment uses MATLAB to do this
𝒙 𝟏 𝟏 𝒙 𝟐 𝟏 ⋯ 𝒙𝑵𝟏 𝝀𝟏 𝟎 ⋯ 𝟎
eigenvectors for this l 𝒙 𝟏 𝟐 𝒙 𝟐 𝟐 ⋯ 𝒙𝑵𝟐 𝟎 𝝀𝟐 ⋯ 𝟎
X= L=
⋮ ⋮ ⋱ ⋮ ⋮ ⋮ ⋱ ⋮
𝒙 𝟏 𝑵 𝒙 𝟐 𝑵 ⋮ 𝒙𝑵𝑵 𝟎 𝟎 ⋮ 𝝀𝑵
87 88

Supplemental Materials Coordinate transformations


• Items not planned for in-class coverage • Recall previous equations
– Matrix equations for coordinate transforms y1  a11x1  a12 x2 z1  b11 y1  b12 y2
– Derivation of 3x3 determinant formula from y2  a21x1  a22 x2 z 2  b21 y1  b22 y2
general determinant formula
• Define matrices so that y = Ax and z = By
– Example of inverse calculation for 4x4
matrix (with many zeros) a a  b b 
– Example of eigenvalue and eigenvector A   11 12  B   11 12 
calculations a21 a22  b21 b22 
• 2 x 2 array x  y  z 
x   1 y   1 z   1
• 3 x 3 array
 x2   y2   z2 
89 90

ME 309 – Numerical Analysis of Engineering Systems 15


Matrix Analysis February 17-19, 2014

Coordinate transformations II Coordinate Transformations III


• Show that matrix definitions give • From matrix equations y = Ax and z =
transformation results By, we have z = BAx = Cx with C = BA
y1  a11x1  a12 x2 z1  b11 y1  b12 y2 a a  b b  c c 
A   11 12  B   11 12  C   11 12 
y2  a21x1  a22 x2 z2  b21 y1  b22 y2 a21 a22  b21 b22  c21 c22 
y  a a  x   a x  a x  c c  b a  b a b a b a 
y   1   Ax   11 12   1    11 1 12 2  C   11 12    11 11 12 21 11 12 12 22 
 y2  a21 a22   x2  a21x1  a22 x2  c21 c22  b21a11  b22a21 b21a12  b22a22 
z  b b  y  b y  b y  z  c c  x  c x  c x 
z   1   By   11 12   1    11 1 12 2  z   1   Cx   11 12   1    11 1 12 2 
 z2  b21 b22   y2  b21 y1  b22 y2   z2  c21 c22   x2  c21x1  c22 x2 
91 92

Example of General Rule Example of General Rule II


• Get determinant of a 3 x 3 matrix by • Get determinant of a 3 x 3 matrix
expansion along last row a31M 31  a32M 32  a33M 33 
a12 a13 a a a a
a11 a12 a13 a31  a32 11 13  a33 11 12 
a21 a22 a23  a31 A31  a32 A32  a33 A33 a22 a23 a21 a23 a21 a22
a31 a32 a33  a31(a12a23  a22a13 )  a32 ( a11a23
A33  (1) 33 M 33 
a11 a12
A22  (1) 22 M 22 
a11 a13  a21a13 )  a33(a11a22  a12a21)
a21 a22 a31 a33  a31a12a23  a31a22a13  a32a11a23
a a a a13
A32  (1) 32 M 32   11 13
a21 a23
A31  (1) 31 M 31  12
a22 a23  a32a21a13  a33a11a22  a33a12a21
93 94

Example Problem Example Problem Det A


• Find A-1 for A at right • Det A = (-1)3+1a31M31 + (-1)3+2a32M32+
1 0 2 1
2 (-1)3+3a33M33 + (-1)3+4a34M34
• Have the following 1 0 0 1 0 2 1 
formula for B = A-1 A   2 1 0 0
1 0 0 0 0 2 1 A 
M ji 31 1 0 0 0 
bij  (1)i  j   Det A  (1) (1) 1 0 0  0  0  0  
Det ( A) 0 2 3 1
2 3 1 0 2 3 1 

0 2 1
• General determinant formula: SaijAij  (0)(0)(1)  (1)(3)(1)  (2)(2)(0)
Det A  1 0 0 1
• Take sum over third row to simplify  (2)(0)(1)  (1)(2)(1)  (0)(3)(0)
calculation of Det A 2 3 1
95 96

ME 309 – Numerical Analysis of Engineering Systems 16


Matrix Analysis February 17-19, 2014

Example Problem III Example Problem Solution


• Apply: bij = (-1)i+jMji/Det A 1 0 2 1 0 0 1 0
1 0 2 1
• 2 2 0 0 1 2 0 
Det A = 1 so bij = (-1)i+jMji 1 0 0 A
1 0
 A 1   
– Examples shown below A 
1 0 0 0  1  2 5 1 
1 0 0 0
     
0 2 1 0 2 3 1 3 4  11  2
0 2 3 1
b12  (1)12 M 21   0 0 0  0 Remove Remove
for M21 for M34 • We can show that AA-1 = A-1A = I
2 3 1
• (AA-1)11 = 1∙0 + 0∙0 + 2∙(-1) + 1∙3 = 1
1 0 2
 3  8  0 • (A-1A)43 = 3∙2 + 4∙0 + (-11)∙0 + (-2)∙3 = 0
b43  (1) 43 M 34   2 1 0   11
 0  0  0 • Only 14 left to check
0 2 3
97 98

Two-by-two Example Two-by-two Example Continued


• Find eigenvalues and 1 5 • Find x(1) components for l1 = 2 A 
1 5
A   2
eigenvectors of A
0 2  • Solve [A – lI]x = 0 for x(1) components 0

1 l 5 (1  2) x(1)1  5 x(1) 2   x(1)1  5 x(1) 2  0


Det[ A  Il]  0 0 x(1)1  (2  2) x(1) 2  0 x(1)1  0 x(1) 2  0
0 2l
• One equation in two unknowns
Det[A  Il]  (1  l)(2  l)  (0)(5)  0
• Pick x(1)2 =  then x(1)1 = 5 from first
• Solutions are l1 = 2 and l2 = 1 equation
99
• Eigenvector x(1) is [5 ]T 100

Two-by-two Example Concluded Check Two-by-two Example


• Next find x(2) components for l2 = 1 1 5 1 5 5   (1)(5 )  (5)( ) 
A Ax (1)       
• Same as approach for finding x(1)1 0  2 0 2    (0)(5 )  (2)( )
(1  1) x( 2)1  5 x( 2) 2  0 x( 2)1  5 x( 2) 2  0 10  5 
   2   l1x (1)
0 x( 2)1  (2  1) x( 2) 2  0 x( 2)1  1x( 2) 2  0  2   
• Both equations give x(2)2 = 0 1 5     (1)(  )  (5)(0) 
Ax ( 2)       
• Pick x(2)1 =  (x(2)1 cannot be determined) 0 2  0  (0)(  )  (2)(0)
• x(2) = [ 0]T    
    1   l2 x ( 2)
101 0 0 102

ME 309 – Numerical Analysis of Engineering Systems 17


Matrix Analysis February 17-19, 2014

Eigenvector Factors Multiple Eigenvalue Example


• 2 x 2 example showed Ax(j) = ljx(j) 2 2  6 2  l 2 6 
regardless of choice of  and  A   2  1  3

A  Il   2  1  l  3 
• This is general result  2  1 1    2  1 1  l 
• We can pick one eigenvector
component; typical choices are to make Det ( A  Il )  (2  l )(1  l )(1  l )  (2)(1)(6)
eigenvector simple or a unit vector  (2)(2)(3)  (2)(1  l )(6)  (2)(2)(1  l )

5  5
5 
  1
 (2  l )(1)(3)  l3  2l2  l  2  12  12  12
x (1)    x (1)    x (1)   26  x ( 2)    x ( 2)   
  1 1  0 0   12l  4  4l  6  3l  l3  2l2  20l  24  0
 26 
103 104

Multiple Eigenvalue Example II Multiple Eigenvalue Example III


2  (2) 2  6   x( k )1  0
Det (A  Il )  (l  2)(l  2)(l  6)  0  2  1  ( 2)
 
 3   x( k ) 2   0

• Solutions are l = 6, –2, –2   2 1 1  (2)  x( k )3  0
• l = –2 has algebraic multiplicity of 2 4 2  6  x( k )1  0 • Apply Gauss
2  
• Find eigenvector(s) from (A – Ilk)x(k) = 0
 1  3  x( k ) 2   0 elimination to
2  lk 2  6   x( k )1  0  2  1 3   x( k )3  0 these equations
 2   • Look at
  1  lk  3   x( k ) 2   0 lk = –2 4 2  6  x( k )1  0 • Pick x(k)3
  2 1 1  lk   x( k )3  0  0 0 0   x   0  and x(k)2
   (k )2   
105
0 0 0   x( k )3  0 106

Multiple Eigenvalue Example IV Continue Example for l3 = 6


• Pick x(k)2 and 2  6 2  6   x(3)1  0 
4 2  6  x( k )1  0   
 0 0 0   x   0  x(k)3 then ( A  Il3 )x (3)  2  1  6  3   x(3) 2   0  0

   (k )2    6 x( k )3  2 x( k ) 2   2  1 1  6  x(3)3  0
0 0 0   x( k )3  0x( k )1 
4  4 2  6  x(3)1  0 • Apply Gauss
• Pick x(k)3 = 2 and x(k)2 = 0 => x(k)1 = 3  2  7  3   x   0 
• Pick x(k)3 = 0 and x(k)2 = 2 => x(k)1 = -1    ( 3) 2    elimination to
 2  1  5  x(3)3  0 these equations
• Two linearly  3  1
independent x  0 x 2    2   4 2  6  x(3)1  0 • Pick x(3)3
eigenvectors 1    0  6  6  x   0 =1 =>
for l = -2 2  0     ( 3) 2   
107
 0 0 0   x(3)3  0 x(3)2 =-1
108

ME 309 – Numerical Analysis of Engineering Systems 18


Matrix Analysis February 17-19, 2014

Example Results Eigenvector Linear Dependence

 4 2  6  x(3)1  0 6 x(3)1  2 x( 3)1 • Can we have 1x(1) + 2x(2) + 3x(3) = 0


x(3)1 
 0  6  6   x   0  4 without 1 = 2 = 3 = 0?
   ( 3) 2    6(1)  2(1)
 0 0 0   x(3)3  0   2  3  1   2 0 
4
1x 1  1x 2    3x 3  1 0   2  2    3   1  0  0
• Eigenvalues l1 = -2, l2 = -2, l3 = 6 have 2  0   1  0
eigenvectors shown below
 3  1   2 3  1  2 1  0 • Homogenous equations
x 1  0 x 2    2  x 3    1 0 2  1    0
  2    have 1 = 2 = 3 = 0 if
2  0   1  2 0 1   3  0 matrix has full rank
109 110

Linear Dependence II Quiz Three Solutions


1. Results of MATLAB commands
• Matrix has full rank it its determinant is 1
not zero 2
>> A = [ 1; 2; 3; 4] 𝐴=
3
 3  1  2 (3)(2)(1)  (0)(0)(2)  4
Det 0 2  1  (2)(1)(1)  (2)(2)(2)  5 6
>> B = [5 6; 7 8; 9 10] 𝐵= 7 8
2 0 1  (0)(1)(1)  (3)(0)(1)  15 9 10
>> C = [A B] Error: A and B must have the
• Since determinant is not zero, the only same number of rows
solution is 1 = 2 = 3 = 0, so 2 6
eigenvectors are linearly independent >> D = [A(2:4,1) B(:,2)] 𝐷= 3 8
111
4 10 112

Quiz Three Solutions II Quiz Three Solutions III


2. Write MATLAB Commands 4. Results of (a) G = [E; [F F]] and (b) H = [F; E’]?
3 5 −6 10 4 7
𝐸= E = [3 5 -6 10; 12 7 -9 4] 3 5 −6 10 −2 9
12 7 −9 4
4 7 12 7 −9 4 6 0
𝐹 = −2 9 F = [4 7; -2 9; 6 0] 𝑮= 4 7 4 7 𝑯 = 3 12
−2 9 −2 9 5 7
6 0
6 0 6 0 −6 −9
3. Results of series of two commands
10 4
>> t = 2:6 (log(2))1, (log(3))2, (log(4))3, 5. G array after the command G(2:4,2:3) = F?
>> x = log(t) .^ (t – 1) (log(5))4, (log(6))5 3 5 −6 10
>> t = 0:pi/4:pi cos(0)/e0, cos(p/4)/ep/4, cos(p/2)/ep/2, 12 4 7 4
>> y = cos(t) ./ exp(t) cos(3p/4)/e3p/4,cos(p)/ep 𝐺 = 4 −2 9 7
−2 6 0 9
>> t = 0:2:10 z = 0 + 2 + 4 + 6 + 8 + 10 = 30
6 0 6 0
>> z = sum(t) 113 114

ME 309 – Numerical Analysis of Engineering Systems 19


Matrix Analysis February 17-19, 2014

First Programming Assignment Comments on Assignment


• Number of students: 20 • Range of methods considered
• Maximum possible score: 40 • Cell formulas are simplest and quickest
• Mean: 31.7 • Use user defined functions (UDF) when
• Median: 34 you have repeated calculations and you
• Standard deviation: 6.94 want to avoid errors in reentering
formulas
• Grade distribution:
• Range names better identify variables
18 21 23 24 25 26 26
– not so important for simple calculations,
30 32 32 36 36 37 but useful for more complex workbooks
37 37 37 38 39 39 40
115 116

Comments on Assignment II Second Quiz


• Array function and macro require a lot of • Number of students: 22
coding which is justified only if • Maximum possible score: 25
calculation is repeated by several users • Mean: 15.9
– With array function multiple tables can be
placed on worksheet, each driven by • Median: 16.5
separate input cells • Standard deviation: 6.63
• Difficult to specify exact number of cells by • Grade distribution:
selection
3 6 7 10 11 11 11
– Macro requires recoding to use other
11 12 13 15 18 20 21 21
inputs or place results in other locations
• Uses exact specification of number of cells
21 22 22 23 23 24 25
117 118

Comments on Second Quiz Second Program


• Confusion over transpose • Number of students: 20
– MATLAB A‘ denotes transpose (usually AT) • Maximum possible score: 40
1 4 • Mean: 26.5
1 2 3
– For 𝐴 = , 𝐴𝑇 = 2 5
4 5 6
3 6
• Median: 27.5
• Expression cos(t).^(t-1) is same as • Standard deviation: 8.8
(cos(t)).^(t-1) NOT cos[(t).^(t-1) • Grade distribution:
• Sum (x), where x is a 1D array gives the 10 10 12 19 19 24 24
a sum of all elements in (For a 2D array 24 27 27 28 30 31
it gives sum of each column 32 34 34 34 35 38 38
119 120

ME 309 – Numerical Analysis of Engineering Systems 20


Matrix Analysis February 17-19, 2014

Second Program Comments MATLAB vs. Excel/VBA


• Do not generate or do not copy output • We have focused on use of MATLAB
or large arrays from command window
• Differences between scripts and – This is similar to entering data on the Excel
functions spreadsheet
– Functions receive variable values through • Less focus on MATLAB programming
argument list, just as functions do in other – This is comparable to VBA
languages like VBA • Many students prefer Excel because of
– Variables in scripts, that are not set in the familiarity
script, use the current value of the variable
in the workspace • Excel/VBA more readily available,
especially in small companies
121 122

Quiz Three Solutions Quiz Three Solutions II


• Initial guesses show that x+ = 3 and x- = 3 − 1.2615
𝑥𝑛𝑒𝑤 = 1.2615 − −0.01133 = 1.2661
1 because f(3) > 0 and f(1) < 0 4.2858 − −0.01133
𝑥+ − 𝑥−
𝑥𝑛𝑒𝑤 = 𝑥− − 𝑓 𝑥− relErr =
1.2615−1.2661
= 0.00362 > 0.001: 𝐜𝐨𝐧𝐭𝐢𝐧𝐮𝐞
𝑓 𝑥+ − 𝑓 𝑥− 1.2661
3− 1
= 1 − −0.5403 = 1.2239 • f(xnew) < 0 so xnew replaces x-
4.2858 − −0.5403
• f(xnew) < 0 so xnew replaces x- 3 − 1.2661
𝑥𝑛𝑒𝑤 = 1.2661 − −0.01130 = 1.2666
3 − 1.2239 4.2858 − −0.01130
𝑥𝑛𝑒𝑤 = 1.2239 − −0.09269 = 1.2615
4.2858 − −0.09269
1.2666−1.2661
1.2615−1.2239 relErr = = 0.000416 < .001: 𝐟𝐢𝐧𝐢𝐬𝐡𝐞𝐝
relErr = 1.2615
= 0.0298 > 0.001: 𝐜𝐨𝐧𝐭𝐢𝐧𝐮𝐞 1.2666

• f(xnew) < 0 so xnew replaces x- x = 1.2666


123 124

Review Last Lecture Review Last Lecture II


• Discussion of matrices: a(row)(column) – Use MATLAB commands det(A) and inv(A)
– Row, column, diagonal, square, unit(I), null(0) for determinant and inverse
– A = B, A ± B, xA, A/x (scalar x), AT – Use Excel formulas mmult(A, B) for matrix
multiplication, mdeterm(A) for determinant,
– Matrix multiplication: P = LR
𝑞
and minverse(A) for inverse
• Columns in L = rows in R = q 𝑝𝑖𝑗 = 𝑘=1 𝑙𝑖𝑘 𝑟𝑘𝑗 • minverse and mmult are array formulas
• P rows = L rows; P columns = R columns – Simultaneous linear equations in general
• Multiply row of L by column of R 𝑁
matrix form, Ax = b 𝑗=1 𝑎𝑖𝑗 𝑥𝑗 = 𝑏𝑖
– Determinants: single number for rectangular • Variables x1, x2, x3, …
array; formula depends on array size • Coefficients aij multiplies xj in equation i
– Inverse, A-1: AA-1 = A-1A = I • Right hand side bi in equation i
125 126

ME 309 – Numerical Analysis of Engineering Systems 21


Matrix Analysis February 17-19, 2014

Review Last Lecture III Review Last Lecture IV


– Linear dependence: if one equation in a – Solution of a system of linear algebraic
system of equations is a linear combination of equations, Ax = b, with n unknowns depends
one or more other equations, the system is of rank of A and [A b]
said to be linearly dependent • Unique solution: rank(A) = rank([A b]) = n
• A system that is not linearly dependent is linearly • Infinite solutions: rank(A) = rank([A b]) < n
independent • No solutions: rank(A)  rank([A b])
• In matrix form an equation is a row – Gaussian elimination: process to get matrix
– Matrix rank = number of linearly independent for system of equations in upper triangular
rows = number of linearly independent form for simple back substitution
columns • Also used to determine rank
– MATLAB formula rank(A) for matrix rank • Will review in detail later
127 128

ME 309 – Numerical Analysis of Engineering Systems 22

You might also like