Escolar Documentos
Profissional Documentos
Cultura Documentos
Third Edition
Tradition & Excellence Since 1821 Mechanical Engineering
TOPIC
ME 354
04 Computations in
Mechanical Engineering
Systems of Linear
Equations
Homogeneous if b = 0.
Nonhomogeneous if b 0
Consistency • The system is said to be consistent if it has at least one solution.
• The system is inconsistent if it has no solution.
04 - 2
Linear Systems: Elementary Equation Operations
• Elementary equation operations (similar to ERO for matrices) on both
sides of the system will not change the solution(s).
General a11x1 a12 x2 a1n xn b1 a21x1 a22 x2 a2n xn b2
Form a21x1 a22 x2 a2n xn b2 a11x1 a12 x2 a1n xn b1
am1x1 am 2 x2 amn xn bm am1x1 am 2 x2 amn xn bm
04 - 6
x3 x3 •rank(A) =rank(Au) = # of leading 1’s = 2 < n = 3
What Determine(s) if Solutions Exist? Example 3
Gen. Form Ax b A b
x1 2 x2 x3 1 1 2 1 x1 1 1 2 1 1
1 2 1 2 –1R1+R2
x1 2 x2 x3 2 1 2 1 x2 2
–1R1+R3
x1 x2 3x3 1 1 1 3 x3 1 1 1 3 1
x1 2 x2 x3 1 1 2 1 x1 1 1 2 1 1
0 x3 1 0 0 0 x2 1 0 0 0 1
R23
x2 2 x3 0 0 1 2 x3 0 0 1 2 0
x1 2 x2 x3 1 1 2 1 x1 1 1 2 1 1
0 1 2 0 • rank(A)=2
x2 2 x3 0 0 1 2 x2 0 –R2 • rank(Au)=3
0 x3 1 0 0 0 x3 1 0 0 0 1 • rank(A)
x1 2 x2 x3 1 1 2 1 x1 1 1 2 1 1 rank(Au)
x2 2 x3 0 0 1 2 x2 0
0 1 2 0
–2R2+R1 • No solution
0 x3 1 0 0 0 x3 1 0 0 0 1
x1 5 x3 1 1 0 5 x1 1 1 0 5 1
x2 2 x3 0 0 1 2 x2 0 0 1 2 0
–R3+R1
0 x3 1 0 0 0 x3 1 0 0 0 1
x1 5 x3 0 1 0 5 x1 0 1 0 5 0
x2 2 x3 0 0 1 2 x2 0 0 1 2 0
0 x3 1 0 0 0 x3 1 0 0 0 1
04 - 7
Rank of A Matrix: Basic Concepts
Rank • The rank of a matrix A, rank(A), is defined as the number of
linearly independent rows or columns.
The number of independent rows equals the number of
independent columns
rank(A) min(m,n) if A is m n.
rank(A) n for a square matrix A of size n.
rank(A) = rank(AT)
Theorem • The elementary row operations (ERO) will not change the rank of
a matrix. The elementary row operations can lead to a simpler
matrix for which the rank can be easily obtained.
Simple • One of the simple forms is the reduced row-echelon form (rref) of
Form the matrix, from the elementary row operations (ERO).
04 - 8
Echelon Form of a Matrix
Echelon Form • A matrix A is said to in (row) echelon form if:
The 1st nonzero element in each row, the
leading entry, is 1. 1 0 5 7 2
For two successive nonzero rows, the 0 0 1 1 3
leading 1 in the lower row is farther to the 0 0 0 1 6
right than the leading 1 in the higher row. 0 0 0 0 0
All zero rows occur at the bottom of the
matrix.
Reduced Row • A matrix A is said to in reduced row-
Echelon Form echelon form, rref(A), if, in addition to the 1 0 0 0 2
0 0 1 0 3
above conditions, it is also true that
In a column that contains the leading 0 0 0 1 6
entry of a row, all other elements are 0 0 0 0 0
zeros.
The columns with a leading entry is called the leading
columns.
Finding A–1 from ERO of [A | I ] is to find the reduced row-
echelon form of [A | I ].
04 - 9
Rank of a Matrix: Calculation
From rref • rank(A) = the number of leading entries in its rref(A).
Example 0 3 4 1 3 1 2 2
3 1 2 2 R12 0 3 4 1 (1/3)R1
1 5 2 1
1 5 2 1
1 1 / 3 2 / 3 2 / 3 1 1 / 3 2 / 3 2 / 3
0 3 4 1 –R1+ R3 0 3 4 1 R23
1 5 2 1 0 14 / 3 4 / 3 1 / 3
1 1 / 3 2 / 3 2 / 3 1 1 / 3 2 / 3 2 / 3 –1/3R + R
0 14 / 3 4 / 3 1 / 3 (3/14) R2 0 1 2 / 7 1 / 14 2 1
– 3R2 + R3
0 3 4 1 0 3 4 1
1 0 4 / 7 9 / 14 1 0 0 1 / 2
0 1 2 / 7 1 / 14 –2/7R3 + R2 0 1 0 0 Rank(A)=3
–4/7R3 + R1
0 0 1 1 / 4 0 0 1 1 / 4
r rank(A) = rank(Au) ru
Example x1
1 2 3 1 r = 1 ru = 2
1 2 3 x2 3
No solution
x3
x1 x1 3 3 x3
1 2 3 1 r = ru = 2 < n, x 1 3 x
1 1 3 x2 2 number of solutions 2 3
x3 x3 x3
04 - 13
Discussions on Existence and Uniqueness: m = n
Review a11 a12 a1n x1 b1
a a22 a2n x2 b2 • r = ru Solutions exist.
21 • r = n: Solution is unique.
a ann xn bn
n1 an 2
m=n • r can be equal to or smaller than n.
• The system may
have no solution (r ru)
have one unique solution (r = ru = n)
have infinite number of solutions (r = ru < n).
Example 1 2 x1 1 r = 1 ru = 2
1 2 x 3
2 No solution
1 2 x1 1 r = ru = 2 = n x1 2
1 1 x 3 x 5
2
One unique solution 2
x1 0 1 0 0 0 0
x2 (1 / 3) x4 0 0 1 0 1/3 0
rref( A u )
x3 (2 / 3) x4 0 0 0 1 2/3 0
0 1 0 0 0 0 1
r = 3
ru = 4
r ru, no solution!!!
04 - 16
Solutions of Linear Systems: One Solution
rref(Au) • Get r , ru and n from the rref(Au). If r = ru = n, one unique solution.
Example 1 2 3 4 1 1 2 3 4 1
x1 4
4 5 6 7 0 5 6 7 0
x2
1 3 6 3 2 A u 1 3 6 3 2
x3
1 2 3 4 1 1 2 3 4 1
x4
1 4 6 8 2 1 4 6 8 2
x1 0 1 0 0 0 0
x2 5 / 3 0 1 0 0 5 / 3
x3 1 rref( A u ) 0 0 1 0 1
x4 1/ 3
0 0 0 1 1 / 3
00 0 0 0 0 0
• r = ru = 4 = n x1 0
x 5 / 3
• One unique solution. 2
x3 1
• The solution is the first 4 x
elements in the last column 4 1/ 3
04 - 17
Solutions of Linear Systems: Infinite # of Solutions
rref(Au) • Get r , ru & n from rref(Au). If x1 x2 x3 x4
r = ru < n r = ru < n, infinite # of solutions. 1 0 2 6 2
0 1 1 11 3
• Look down the columns of
rref(A), if column j is NOT a 0 0 0 0 0
leading column, then xj is
0 0 0 0 0
independent (arbitrary), otherwise
0 0 0 0 0
xj is dependent.
• r = ru = 2 < n = 4, inf # sol.
• Each nonzero row of rref(Au)
• 2 independent: x3 & x4
represents an equation in the
reduced system, having one (and x1 2 x3 6 x4 2
only one) dependent unknown,
and all other unknowns in this
x2 x3 11 x4 3
equation (if any) independent.
Solutions x1 6 x4 0 6 0 6
x 11x 0 11 0 11
2 4 x4 c c is any
x3 1 / 3 4 x4 1 / 3 4 1 / 3 4 constant
x x 0 1
4 4
0 1
04 - 19
Linear Systems with A Square A (m=n)
Matrix a11 a12 a1n x1 b1
Form a a22 a2n x2 b2 • r = ru: Solutions exist.
21 • r = n: Solution is unique.
a ann xn bn
n1 an 2
Rank of a • r n.
Square • r = n, if det(A) 0. The matrix is said to be full ranked.
Matrix • If det(A) = 0, then r < n, and A is said to be rank deficient.
• For a full ranked matrix, rref(A) = I
04 - 20
Homogeneous Systems with Square A (m=n)
Matrix a11 a12 a1n x1 0
Form a a22 a 2 n x2 0
21 or Ax = 0
a ann xn 0
n1 an 2
s2 = 9 16 13 16 x1 0 1 0 1 x1 1
13 19 13 x 0 rref ( A ) 0 1 0 x 0 c
2 2
16 13 16 x3 0 0 0 0 x3 1
s3 = 3 10 13 16 x1 0 1 0 1 x1 1
13 13 13 x 0 rref ( A ) 0 1 2 x2 2 c
2
16 13 10 x3 0 0 0 0 x3 1
Note • It can be easily verified that the three principal directions are
orthogonal.
04 - 23
Nonhomogeneous Systems with Square A (m=n)
Matrix a11 a12 a1n x1 b1
Form a a22 a2n x2 b2
21 or Ax = b
a ann xn bn
n1 an 2
Cramer’s The nonhomogeneous system has unique solution if and only if
Rule it is invertible.
Proof r = n for an invertible matrix A.
the “if ” n = r ru n ru= n=r and the system has a unique solution
If A is singular, either there is no solution (r ru) or there are
infinite number of solutions (r = ru < n)
How to • Use A–1
Solve • Use rref(Au) (also called Gauss-Jordan elimination).
• Gaussian elimination [similar to using rref(Au)]
• LU factorization.
04 - 24
• MATLAB©
Nonhomogeneous Systems: Use A–1
Matrix a11 a12 a1n x1 b1
Form a a22 a2n x2 b2
21 or Ax = b
a ann xn bn
n1 an 2
Theorem • The above system has a unique solution if and only if the matrix A
is invertible, and the solution is
x = A–1b
Proof Ax b, A 1Ax A 1b, Ix A 1b, x A 1b
Example 3 5 x1 10 1 2 5 / 2
2 4 x 8 A
2 1 3 / 2
2 5 / 2 10 0
1
xA b
1 3 / 2 8 2
Note • This is generally less efficient than other approaches.
• If A is singular, this method can not be used.
04 - 25
Nonhomogeneous Systems: Use rref(Au)
Conclusions • The system has a unique solution if and only if r = ru = n , and
the reduced row-echelon form of A is an identity matrix of size n.
The solution is the last column of rref(Au).
Procedure • The procedure is the same as that for solving the linear systems
with a non-square A, as discussed previously.
04 - 26
Nonhomogeneous Systems Using rref(Au): Examples
Examples 4 2 0 x1 1 1 0 0 3 / 4 3 / 4
2 1 3 x 2 rref ( A ) 0 1 0 2 x 2
2 u
2 2 1 x3 3 0 0 1 1 / 2 1 / 2
4 2 0 x1 1 1 1 / 2 0 0 • r=2
2 1 3 x 2 rref ( A ) 0 0 1 0 • ru = 3
2 u
2 1 3 x3 3 0 0 0 1 • no solution
x1 x2 x3 RHS
1 1 3 x1 2 1 1 3 2 •r = r = 1 < n
u
4 4 12 x 8 rref ( A ) 0 0 0 0 •Infinite # of
2 u
2 2 6 x3 4 0 0 0 0 solutions
2 x2 3 x3 2 s 3t
x x2 s
s and t are arbitrary
x3 t
04 - 27
Gaussian Elimination
Gaussian • The Gaussian elimination is similar to the approach using rref(Au).
Elimination • The major difference is to make A an upper triangular matrix,
instead of an identity matrix when using rref(Au).
• Two stages in the approach: elimination & back substitution.
Elimination • Perform ERO on Au to make A an upper triangular matrix
a11 a1 n
a12 b1
a11 a1 n x1 b1
a12
0 a b2 0 a x b
22 a2 n or a
22 2 n 2 2
0 0 0 0
0 bn 0 x b
0 ann 0 0 a
nn n n
Back • The equation can be solved starting from xn, xn–1, …, x1:
Substitution b 1
xn n xn 1 (bn 1 an 1n xn )
ann an 1n 1
1 n
xi
i
b
ik k i n 1, n 2,,1
a x
aii k i 1
04 - 29
Computationally, this method is more efficient than to get the rref(Au).
Gaussian Elimination Example
1 1 1 x1 3 1 1 1 3
Elimin.
4 3 4 x2 8 A u 4 3 4
R13
8
or (why?)
9 3 4 x3 7 9 3 4 7
9 3 4 7 9 3 4 7
4 3 4 (– 4/9)R1+R2 (– 2/5)R2+R3
8 0 5 / 3 20 / 9 44 / 9
(– 1/9)R1+R3 No switch
1 1 1 3 0 2 / 3 5 / 9 20 / 9
9 3 4 7 9 x1 3x2 4 x3 7
0 5 / 3 20 / 9 44 / 9
or 5 / 3x2 20 / 9 x3 44 / 9
0 0 1 / 3 4 / 15 1 / 3x3 4 / 15
Back 4 / 15 4
x3
Subst. 1/ 3 5
x1 1 / 5
44 / 9 (20 / 9) x3 44 / 9 (20 / 9)(4 / 5) x 4
x2 4 2
5/3 5/3
x3 4 / 5
7 3x2 4 x3 7 3(4) 4(4 / 5) 1
x1
9 9 5
04 - 30
LU Factorization: Motivation
Motivation • It can be seen, from the Gaussian elimination method, that if the
matrix A in the linear system Ax=b is triangular, the solution
can be easily obtained.
If A is an upper triangular matrix (as in the Gaussian
elimination) , the system can be solved from the back
substitution (solving from xn to x1).
If A is a lower triangular matrix, the system can be solved
from the forward substitution (solving from x1 to xn).
LU • The LU factorization approach is to factor the matrix A into the
Factorization product of two triangular matrices: A=LU. L and U are the
lower and upper triangular matrices.
The original equation Ax=b becomes LUx=b . If let Ux=y,
then Ly=b. We have two systems with triangular matrices.
Solve for y from Ly=b from the back substitution.
With y known, solve for x from Ux=y from the forward
substitution.
04 - 31
LU Factorization: Solution
Equations 1 0 0 y1 b1
l 1 0 y2 b2
Ly = b 21
Ax = b l 1 yn bn
n1 ln 2
LUx = b
u11 u12 u1n x1 y1
y 0 u22 u2n x2 y2
Ux = y
0 unn xn yn
0
Forward • Solve Ly=b first for y (forward substitution):
Subs. for y i 1
y1 b1, y2 b2 l21 y1, yi bi lik yk i 2,, n
k 1
1 0 0
l 1 0
• A unit lower triangular
L 21 matrix with all diagonal
elements equal to 1
l 1
n1 ln 2
How to Get • (1st row of L) (All columns of U) 1st row of U, u1j = a1j
lij and uij?
• (2nd row of L) (All columns of U) 2nd rows of L and U:
l21 a21 / u11, u2 j a2 j l21u1 j
• (ith row of L) (All columns of U) ith rows of L and U:
j 1 i 1
lij (aij lik ukj ) / u jj , uij aij lik ukj ,
k 1 k 1
j = 1, 2, …, i –1 j = i, i+1, …, n
See Ex04_01.m
04 - 35
MATLAB© Solutions of Linear Systems
Operation Command Comments
inv(A)*b A–1 b For a square invertible A only.
A\b Solve Ax=b • Gives one solution only even if
more than one exists.
• Solve the system with least
square if no solution exists.
• More accurate than inv(A)*b
rref(Au) Get the rref(Au) Define Au=([A b])first.
rrefmovie(Au)
[L U P]=lu(A) LU factorization • LU factorization with pivoting.
• P is the permutation matrix,
revealing row exchange info.
rank(A) rank(A)
cond(A) Condition number • Large condition numbers
with respect to A–1 indicate a nearly singular matrix
04 - 36