Download presentation
Presentation is loading. Please wait.
Published byDenis Gardner Modified over 9 years ago
1
1 Linear Algebraic Equations and Matrices
2
Three Individuals Connected by Bungee Cords
3
Free-body Diagrams Newton’s second law 3 Rearrange equations [K] {x} = {b}
4
Newton’s Second Law – Equation of Motion Mass-spring system (similar to bungee jumpers) Kirchhoff’s current and voltage rules 4 Resistor circuits
5
Solved a single equation Now consider more than one variable and more than one equation Linear Algebraic Equations
6
Linear Systems Linear equations and constant coefficients a ij and b i are constants 6
7
Mathematical Background Write system of equations in matrix-vector form 7
8
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
9
向量的乘法、除法 向量的乘法 >>x=[1 2 3]; >>pi*x % 純量乘向量 ans = 3.1416 6.2832 9.4248 >>x=[1 2 3]; >>y=[4 5 6]; >>x.*y % 向量乘向量 ans = 4 10 18 9 向量的除法運算在代數系統 實未定義,但在 MATLAB 中 x./y 表示 x.\y 表示 >>x=[1 2 3]; >>y=[4 5 6]; >>x./y % 向量除向量 ans = 0.2500 0.4000 0.5000
10
Matrix Notations 10 Column 4 Row 3 (second index) (first index)
11
矩陣的索引與下標 11
12
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
13
Matrix Operations Transpose ( 轉置 ) In MATLAB, transpose is A Trace is sum of diagonal elements In MATLAB, trace(A) 13
14
Matrix Transpose 14
15
Special Matrices Symmetric matrices 15 a ij = a ji [A] T = [A]
16
Special Matrices Diagonal matrix 16 [A][I] = [I][A] = [A] Identity matrix ( 單位矩陣 )
17
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
18
Special Matrices Lower triangular Upper triangular 18
19
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
20
g = 5 Multiplication of Matrix by a Scalar
21
Matrix Multiplication Visual depiction of how the rows and columns line up in matrix multiplication 21
22
[A]*[B] [B]*[A] Matrix Multiplication
23
Matrix multiplication can be performed only if the inner dimensions are equal 23
24
Matrix Multiplication Interior dimensions have to be equal For a vector We will be using square matrices 24
25
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
26
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
27
Augmentation Whatever you do to left-hand-side, do to the right- hand side (useful when solving system of equations) 27
28
Augmented Matrix
29
>> A = [1 5 3 -4; 2 5 6 -1; 3 4 -2 5; -1 3 2 6] A = 1 5 3 -4 2 5 6 -1 3 4 -2 5 -1 3 2 6 >> A' ans = 1 2 3 -1 5 5 4 3 3 6 -2 2 -4 -1 5 6 Create a matrix Matrix transpose MATLAB Matrix Manipulations
30
Matrix concatenation >> x = [5 1 -2 3]; >> y = [2 -1 4 2]; >> z = [3 -2 1 -5]; >> B = [x; y; x; z] B = 5 1 -2 3 2 -1 4 2 5 1 -2 3 3 -2 1 -5 >> C = A + B C = 6 6 1 -1 4 4 10 1 8 5 -4 8 2 1 3 1 >> C = C – B ( = A) C = 1 5 3 -4 2 5 6 -1 3 4 -2 5 -1 3 2 6
31
MATLAB Matrix Manipulations Matrix multiplication, element-by-element operation 31 A = 1 5 3 -4 2 5 6 -1 3 4 -2 5 -1 3 2 6 B = 5 1 -2 3 2 -1 4 2 5 1 -2 3 3 -2 1 -5 >> A*B ans = 18 7 8 42 47 5 3 39 28 -13 19 -14 29 -14 16 -21 >> A.*B ans = 5 5 -6 -12 4 -5 24 -2 15 4 4 15 -3 -6 2 -30 A*B A.*B
32
>> D = [2 4 3 1; 3 -5 1 2; 1 -1 3 2] D = 2 4 3 1 3 -5 1 2 1 -1 3 2 >> A*D ??? Error using ==> * Inner matrix dimensions must agree. >> D*A ans = 18 45 26 9 -6 0 -19 10 6 18 -5 24 A = 1 5 3 -4 2 5 6 -1 3 4 -2 5 -1 3 2 6 Inner dimension must agree A*D D*A MATLAB Matrix Manipulations
33
>> A = [1 5 3 -4; 2 5 6 -1; 3 4 -2 5; -1 3 2 6] >> format short; AI = inv(A) AI = -0.2324 0.2520 0.1606 -0.2467 0.2428 -0.1397 0.0457 0.1005 -0.1436 0.2063 -0.0862 0.0104 -0.1123 0.0431 0.0326 0.0718 >> A*AI ans = 1.0000 0 0 -0.0000 -0.0000 1.0000 0 0.0000 0.0000 0 1.0000 -0.0000 0.0000 0 0.0000 1.0000 Matrix Inverse MATLAB Matrix Manipulations
34
>> A = [1 5 3 -4; 2 5 6 -1; 3 4 -2 5; -1 3 2 6] >> I = eye(4) I = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 >> Aug = [A I] Aug = 1 5 3 -4 1 0 0 0 2 5 6 -1 0 1 0 0 3 4 -2 5 0 0 1 0 -1 3 2 6 0 0 0 1 >> [n, m] = size(Aug) n = 4 m = 8 Matrix Augmentation MATLAB Matrix Manipulations
35
[K] {x} = {b} JumperMass (kg)Spring constant (N/m)Unstretched cord length (m) Top (1)605020 Middle (2)7010020 Bottom (3)805020 Bungee Jumpers
36
>> k1 = 50; k2 = 100; k3 = 50; >> K=[k1+k2 -k2 0;-k2 k2+k3 -k3;0 -k3 k3] K = 150 -100 0 -100 150 -50 0 -50 50 >> format short >> g = 9.81; mg = [60; 70; 80]*g mg = 588.6000 686.7000 784.8000 >> x=K\mg x = 41.2020 55.9170 71.6130 >> xi = [20; 40; 60]; >> xf = xi + x xf = 61.2020 95.9170 131.6130 >> x = inv(K)*mg x = 41.2020 55.9170 71.6130 k 1 = 50 k 2 = 100 stiffer cord k 3 = 50 Final positions of bungee jumpers
37
Kirchhoff’s Current and Voltage Rules Example 8.3 37 i 43 i 32 i 54 i 52 i 65 i 12
38
Kirchhoff’s Current and Voltage Rules Example 8.3 38
39
>> A = [1 1 1 0 0 0 0 -1 0 1 -1 0 0 0 -1 0 0 1 0 0 0 0 1 -1 0 10 -10 0 -15 -5 5 -10 0 -20 0 0]; >> b = [0 0 0 0 0 200]'; >> current = A\b current = 6.1538 -4.6154 -1.5385 -6.1538 -1.5385
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.