1 Linear Algebraic Equations and Matrices
Three Individuals Connected by Bungee Cords
Free-body Diagrams Newton’s second law 3 Rearrange equations [K] {x} = {b}
Newton’s Second Law – Equation of Motion Mass-spring system (similar to bungee jumpers) Kirchhoff’s current and voltage rules 4 Resistor circuits
Solved a single equation Now consider more than one variable and more than one equation Linear Algebraic Equations
Linear Systems Linear equations and constant coefficients a ij and b i are constants 6
Mathematical Background Write system of equations in matrix-vector form 7
Solving Systems of Linear Equations Two ways to solve systems of linear algebraic equations [A]{x}={b} Left-division x = A\b Matrix inversion x = inv(A)*b Matrix inversion only works for square, non- singular systems Less efficient than left-division 8
向量的乘法、除法 向量的乘法 >>x=[1 2 3]; >>pi*x % 純量乘向量 ans = >>x=[1 2 3]; >>y=[4 5 6]; >>x.*y % 向量乘向量 ans = 向量的除法運算在代數系統 實未定義,但在 MATLAB 中 x./y 表示 x.\y 表示 >>x=[1 2 3]; >>y=[4 5 6]; >>x./y % 向量除向量 ans =
Matrix Notations 10 Column 4 Row 3 (second index) (first index)
矩陣的索引與下標 11
Scalars, Vectors, Matrices MATLAB treats variables as “matrices” Matrix (m n) - a set of numbers arranged in rows (m) and columns (n) Scalar: 1 1 matrix Row Vector: 1 n matrix Column Vector: m 1 matrix 12
Matrix Operations Transpose ( 轉置 ) In MATLAB, transpose is A Trace is sum of diagonal elements In MATLAB, trace(A) 13
Matrix Transpose 14
Special Matrices Symmetric matrices 15 a ij = a ji [A] T = [A]
Special Matrices Diagonal matrix 16 [A][I] = [I][A] = [A] Identity matrix ( 單位矩陣 )
Special Matrices Banded matrix – all elements are zero, with the exception of a band centered on the main diagonal 17 Tridiagonal – three non-zero bands
Special Matrices Lower triangular Upper triangular 18
Matrix identity [A] = [B] if and only if a ij = b ij for all i and j Matrix addition and subtraction [C] = [A] + [B] C ij = A ij + B ij [C] = [A] [B] C ij = A ij B ij Commutative [A] + [B] = [B] + [A] [A] [B] = [B] + [A] Associative ( [A] + [B] ) + [C] = [A] + ( [B] + [C] ) ( [A] + [B] ) [C] = [A] + ( [B] [C] ) ( [A] [B] ) + [C] = [A] + ( [B] + [C] ) Matrix Operations
g = 5 Multiplication of Matrix by a Scalar
Matrix Multiplication Visual depiction of how the rows and columns line up in matrix multiplication 21
[A]*[B] [B]*[A] Matrix Multiplication
Matrix multiplication can be performed only if the inner dimensions are equal 23
Matrix Multiplication Interior dimensions have to be equal For a vector We will be using square matrices 24
Matrix Multiplications MATLAB performs matrix multiplication automatically A*B = C Note: no period ‘.’ (not element-by-element operation) For vectors A*x = b Associative ( [A] [B] ) [C] = [A] ( [B] [C] ) Distributive [A] ( [B] + [C] ) = [A] [B] + [A] [C] ([A] + [B] ) [C] = [A] [C] + [B] [C] Not generally commutative [A] [B] [B] [A] 25
Matrix Inverse Matrix division is undefined However, there is a matrix inverse for non-singular square matrices [A] -1 [A] = [A] [A] -1 = [I] Multiplication of a matrix by the inverse is analogous to division 26
Augmentation Whatever you do to left-hand-side, do to the right- hand side (useful when solving system of equations) 27
Augmented Matrix
>> A = [ ; ; ; ] A = >> A' ans = Create a matrix Matrix transpose MATLAB Matrix Manipulations
Matrix concatenation >> x = [ ]; >> y = [ ]; >> z = [ ]; >> B = [x; y; x; z] B = >> C = A + B C = >> C = C – B ( = A) C =
MATLAB Matrix Manipulations Matrix multiplication, element-by-element operation 31 A = B = >> A*B ans = >> A.*B ans = A*B A.*B
>> D = [ ; ; ] D = >> A*D ??? Error using ==> * Inner matrix dimensions must agree. >> D*A ans = A = Inner dimension must agree A*D D*A MATLAB Matrix Manipulations
>> A = [ ; ; ; ] >> format short; AI = inv(A) AI = >> A*AI ans = Matrix Inverse MATLAB Matrix Manipulations
>> A = [ ; ; ; ] >> I = eye(4) I = >> Aug = [A I] Aug = >> [n, m] = size(Aug) n = 4 m = 8 Matrix Augmentation MATLAB Matrix Manipulations
[K] {x} = {b} JumperMass (kg)Spring constant (N/m)Unstretched cord length (m) Top (1) Middle (2) Bottom (3) Bungee Jumpers
>> k1 = 50; k2 = 100; k3 = 50; >> K=[k1+k2 -k2 0;-k2 k2+k3 -k3;0 -k3 k3] K = >> format short >> g = 9.81; mg = [60; 70; 80]*g mg = >> x=K\mg x = >> xi = [20; 40; 60]; >> xf = xi + x xf = >> x = inv(K)*mg x = k 1 = 50 k 2 = 100 stiffer cord k 3 = 50 Final positions of bungee jumpers
Kirchhoff’s Current and Voltage Rules Example i 43 i 32 i 54 i 52 i 65 i 12
Kirchhoff’s Current and Voltage Rules Example
>> A = [ ]; >> b = [ ]'; >> current = A\b current =