Professional Documents
Culture Documents
Chapter 3 - Systems of Equations
Chapter 3 - Systems of Equations
Last lecture:
Muller’s method
Repeated roots
Linear system of equations
This lecture:
Linear algebra:
Determinant
Matrix operations
Eigenvalue Problems
Chapter 3
SYSTEM OF EQUATIONS
Linear Systems
• Need to solve linear equations for x’s with constant coefficients
am 1 am 2 am 3 am 4 amn
3.1.1 Definitions of numerous special matrices
• upper triangular
𝑎11 𝑎12 𝑎13 𝑎14
0 𝑎22 𝑎23 𝑎24
[𝐴] = 0 0 𝑎33 𝑎34
0 0 0 𝑎44
zeroes
3.1.1 Definitions of numerous special matrices
𝑎11 𝑎12 0 0
𝑎21 𝑎22 𝑎23 0 Tridiagonal –
[𝐴] =
0 𝑎32 𝑎33 𝑎34
3 non-zero bands
0 0 𝑎43 𝑎44
band
Transpose of A:
𝑥= 4 −2 3 ; 𝑦 = 3 1 −2
4 3
′
𝑥 = −2 ; y′ = 1
3 −2
• Symmetric matrices
𝑎 𝑏 𝑐 𝑑
𝑏 𝑒 𝑓 𝑔 aij = aji
[𝐴] =
𝑐 𝑓 ℎ 𝑖 T
𝑑 𝑔 𝑖 𝑗 [A] = [A]
5 2 −1 4 6
2 −2 8 −5 1
[𝐵] = −1 8 3 2 0
4 −5 2 1 3
6 1 0 3 −4
Matrix Determinant
Compute the determinant D
2 x 2 matrix D = a11 a12 = a a − a a
11 22 12 21
a11 a12
a21 a22
a21 a22
3 x 3 matrix
Minor Mij = determinant of the matrix after ith row and jth column of A are crossed out
Matrix Determinant
5 7 3 4
Example: 8 9 2 3
D=
1 5 3 8
3 6 9 0
9 2 3 8 2 3 8 9 3 8 9 2
=5* 5 3 8 -7* 1 3 8 +3* 1 5 8 -4* 1 5 3 = -36
6 9 0 3 9 0 3 6 0 3 6 9
5 7 3 4
Example: 8 9 2 3 Choose the row or column with many zeroes.
D=
1 5 3 8
3 6 9 0
5 7 3 5 7 3 5 7 3
=-4* 8 9 2 + 3∗ - 8∗ 8 9 2 + 0∗ 8 9 2
= -36
1 5 3 1 5 3 1 5 3
3 6 9 3 6 9 3 6 9
No need to calculate
Do not use this method for D if n>3 unless there are a lot of zeros in matrix.
3.1.2 Matrix Operations
Matrix identity
[A] = [B] if and only if aij = bij for ALL i and j
Matrix Addition and Subtraction
[C] = [A] + [B] Cij = Aij + Bij
[C] = [A] − [B] Cij = Aij − Bij
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 Multiplication
➢ How the rows and columns line up in matrix multiplication?
3 1
Consider 5 9
A B = 8 6
7 2
0 4
5 9
7 2
3 1 3x5+1x7=22 29
8 6
82 84
0 4 28 8
Matrix Multiplications
g j ga + jd gb + je gc + jf
h k a b c
= ha + kd hb + ke hc + kf
d e
i l
f
ia + ld ib + le ic + lf
[A]*[B] [B]*[A]
Matrix Multiplication
➢ Matrix multiplication can be performed only if the inner dimensions are equal
For C = AB
for i =1 to m
for j=1 to l
A is singular
A is singular
Goal: Given an nxn matrix A, find scalar and nonzero vector x such that
Ax=x
’s are eigenvalues, and x is corresponding eigenvector
Consider A=
4 −1 (A- I) x = 0
−2 3
o The equation for finding is: det (A - I) = 0
NOTE: one of the equations is redundant.
4 − −1
=0
−2 3 − Just pick one to work with.
ሺ4 − 𝜆)ሺ3 − 𝜆) − 2 = 0
𝜆2 − 7𝜆 + 10 = 0 is characteristic polynomial
Choose 𝑥2 =1 𝑥1 = 0.5
ሺ𝜆 − 2)ሺ𝜆 − 5) = 0
o The solution for the eigenvalues is thus: 𝜆1 = 2 & 𝜆2 = 5 𝑥1 (1)
0.5
𝑥 =
o Eigenvector #1 (for 𝜆 = 𝜆1 = 2): 2 1
Eqn: (A - 1 I) x = 0
2𝑥1 − 𝑥2 = 0
& −2𝑥1 + 𝑥2 = 0
Lecture 10
Last lecture:
Determinant
Matrix operations
Eigenvalue problems
This lecture:
Eigenvalue decomposition
Cramer's rule
Matrix norm
Gauss elimination
Eigenvalue Value Decomposition
❖ Given an nxn matrix A, suppose there are n ’s and nonzero vector x such that
A x (i) = i x (i) for i=1,2,…n
i.e.,
𝜆1 0 0 … 0
0 𝜆2 0 … 0
A [x (1) x (2) x (3) … x (n) ] = [x (1) x (2) x (3) … x (n) ] 0 0 𝜆3 … 0
… … … ... …
0 0 0 . . . 𝜆𝑛
❖ Let P = [x (1) x (2) x (3) … x (n) ] = nxn matrix , D = diag()= diagonal matrix with dii = i.
AP=PD
❖ Multiply P-1 from the left on both sides,
P-1 A P = P-1 P D = D
=> A = P D P-1
❖ mth power of A: Am = (P D P-1) m = P D P-1 * P D P-1 * P D P-1 …* P D P-1 = P D m P-1
If max(| i|) <1, Am → 0 for large m (very important for proving convergence of iterative methods)
3.1.3 Cramer's rule for system of equations
a11 x1 + a12 x2 = b1 a22b1 − a12b2 a11b2 − a21b1
x1 = , x2 =
a21 x1 + a22 x2 = b2 a22 a11 − a12 a21 a22 a11 − a12 a21
a11 a12
Denominator is D=
a21 a22
b1 a12
Numerators are:
D1 = a22b1 − a12b2 =
b2 a22
a11 b1
D2 = a11b2 − a21b1 =
a12 b2
D (new matrix) kth column of as with bs (i.e., aik bi )
xk = k
D(a ij )
Dk
Cramer’s Rule
an1 x1 + an 2 x2 + + ann xn = bn
Replace kth column of as with bs (i.e., aik bi )
𝐷(𝑛𝑒𝑤 𝑚𝑎𝑡𝑟𝑖𝑥 ሻ
𝑥𝑘 =
D(aijሻ
Example
3 1 − 1 x1 2 − − −(1)
Find solution to 1 4 1 x = 12 − − −(2) using Cramer’s rule
2
2 1 2 x3 10 − − −(3)
Solution:
3 1 −1 2 1 −1
D 1 28
D = 1 4 1 = ... = 28 x1 = 1 = 12 4 1 = =1
D 28 28
2 1 2 10 1 2
3 2 −1 3 1 2
D 1 56 D3 1 84
x2 = 2 = 1 12 1 = =2 x3 = = 1 4 12 = =3
D 28 28 D 28 28
2 10 2 2 1 10
◊ Cauchy-Schwartz inequality:
For all real or complex valued vectors u and v ,
|<u, v>|2 ≤ <u, u> <v, v>
or |<u, v>| ≤ || u ||2 || v ||2
3.2.3 Lp-norm of a matrix A
row sum:
Define
5 −5 −7 17
𝑛 max= 17
A= −4 2 −4 10
= max. column sum norm = 𝐴 ∞
𝑝 = 1, 𝐴 1 = max 𝑎𝑖𝑗 −7 −4 5 16
1≤𝑗≤𝑛
𝑖=1
column sum: 16 11 16
𝑛
n n
𝐴 = 52 + −5 2 + −7 2 + ⋯ + −4 2 + 52 =15
Ae= aij2 = Frobenius norm 𝑒
i =1 j =1 or Euclidean norm
90 −5 −54
Note: || A ||2 = spectral norm = max{|i|1/2}
A*A= −5 40 7
= smallest among all norms −54 7 90
where i’s are the eigenvalues of (A*A). eig(A*A)= 35.7666, 44.5113, 144.7221
& A* = conjugate transpose of A.
2 =144.7221
𝐴 1/2=12.0301
3.3 Gauss Elimination Method and Gauss-Jordan Method
◊ It is a direct method (in contrast to iterative method)
◊ It is good for dense matrix (i.e. aij have very few zeroes).
3.3.1 Gauss elimination method
3 1 − 1 x1 2 − − −1
◊ Example: Solve x in : 1 4 1 x = 12 − − −2
2 pivot
2 1 2 x3 10 − − −3
element
Soln. 3 1 −1 2 ....1
i. Augmented matrix: [A | b] = 1 4 1 12 ....2
2 1 2 10 ....3
ii. Reduction (to reduce A to an upper triangular matrix)
Reduce the 1st column below a11:
R1=> R 1’ [3 1 -1 2 … (1’)
Scratch: R 2: [1 4 1 12 ] =a21/a11
R 1 * (1/3): [1 1/3 -1/3 2/3 ]
1
Subtract [0 11/3 4/3 11
3 ]
pivot row [3 1 -1 2] … (1’)
Need to reduce 2 to 0
R3- R1’ * (2/3) => R3’:
Scratch: R3: [2 1 2 10 ]
R1 * (2/3): [2 2/3 -2/3 4/3 ]
Result is:
3 1 −1 2 ....1' Pivot
0 3.6667 1.3333 11.3333 ....2 ' element
for 2nd
0 0.3333 2.6667 8.6667 ....3'
column
Gauss elimination
3.3 Gauss Elimination Method and Gauss-Jordan Method
Soln. 3 1 −1 2 ....1
i. Augmented matrix: [A | b] = 1 4 1 12 ....2
2 1 2 10 ....3
ii. Reduction (to reduce A to an upper triangular matrix)
3 1 −1 2 ....1"
0 3.6667 1.3333 11.3333 ....2"
0 0 2.5455 7.6365 ….3
1 0 0 3 1 −1
L = 1/ 3 1 0 U= 0 3.6667 1.3333
0 0 2.5455
2 / 3 1/11 1
3 1 −1 2 ....1" 3x1+x2-x3=2
iii. Back substitution 0 3.6667 1.3333 11.3333 ....2" 3.6667x2+1.3333x3=7.6365
0 0 2.5455 7.6365 ....3" 2.5455x3= 7.6365
a31 a a a
Row3- Row1* a31 / a11: a31 − a11 x1 + a32 − 31 a12 x2 + ... + a3n − 31 a1n xn = b3 − 31 b1
a11 a11 a11 a11
…
Repeat the elimination of ai2 and get
a11 x1 + a12 x2 + a13 x3 + + a1n xn = b1
x2 + a23
a22 x3 + + a2 n xn = b2
a
x3 +
a33 + a3n xn = b3 = b3 − 32 b2
a22
an3 x3 + xn = bn
+ ann
f 32 = a32
'
/ a22
➢ Multipliers used in reducing the 2nd column: f 42 = a42
'
/ a22
...
Gauss Elimination
( n −1)
ann xn = bn( n −1)
f 43 = a43
"
/ a3"3
➢ Multipliers used in reducing the 3rd column:
f53 = a53
" "
/ a33
...
Back Substitution
1 0 −0.4545 0.3636 . . . . 𝑖′
* (row i) - (row ii)*0.3333
0 1 0.3636 3.0909 . . . . 𝑖𝑖′
0 0 1 3.0 . . . . 𝑖𝑖𝑖′
𝑅𝑖′ + 0.4545 × ∗ሺ𝑅 3∗) ⇒ 𝑅 1∗ 1 0 0 1 ....1 ∗
R 𝑖𝑖′ − 0.3636 × ሺ𝑅 3 ∗) ⇒ 𝑅 2 ∗ 0 1 0 2 ....2 ∗ x = (x1, x2, x3)T = (1.0000, 2.0000, 3.0000)T.
ሺ𝑟𝑜𝑤 𝑖𝑖𝑖′) ⇒ 𝑅 3 ∗ 0 0 1 3 ....3 ∗
• Gauss-Jordan method involves 50% more work.
◊ Exact solution is (x1, x2, x3)T = (1, 1, 1)T. x2 = (-8002 + 4005 x3 )/(-3997) = 0.762
◊ Augmented matrix: −0.002 4 4 7.998 −− −1 x1 = (7.998 - 4.0 x3 -4.0 x2) / (-0.002) = 1.0
−2 2.906 −5.387 −4.481 −− −2
3 −4.031 −3.112 −4.143 −− −3
◊ inaccurate results due to round off error.
◊ Reduction using standard Gaussian elimination
& keep ONLY 4 significant digits: ◊ If aii=0, we have to interchange rows in
order to continue the computation.
R2 – (-2)/(-0.002)*R1, R3 – (3)/(-0.002)*R1,
−0.002 4 4 𝑥1 7.998 − −1 𝑥1
3 −4.031 −3.112 −4.143 … 1′
−2 2.906 −5.387 𝑥2 = −4.481 − −2 𝑥2 = −4.481 … 2′
−2 2.906 −5.387
3 −4.031 −3.112 𝑥3 −4.143 − −3 𝑥3
−0.002 4 4 7.998 … 3′
Rearrange A by exchanging row 3 with row 1
3 −4.031 −3.112 −4.143… 1
The element with the largest magnitude in the column is now f21= -0.6667 0 0.2187 −7.4616 −7.243… 2
in the pivot position (as diagaonl element) f31= -0.6667E-4 0 3.997 3.998 7.995 … 3
◊ Back substitution:
x3 = −7.680 /(−7.680) = 1.000
x2 = (7.995 -3.998)/3.997 =1.000
x1 = (−4.143 + 4.031 + 3.112)/3 =1.000
which are exact within 4 significant digits
Lecture 12
Last lecture:
Gauss elimination
Gauss -Jordan Method
Pivoting
This lecture:
𝑎11 𝑎12
2×2 = 𝑎11∗𝑎22 − 𝑎12∗𝑎21 2 M/D
𝑎21 𝑎22
n (n+1)! n3/3
10 3628800 333
20 2.4329E+18 2667
40 8.1592E+47 21333
How much does it cost? $2.5E+37 • 2018 US GDP= $ 20.54 trillion = $ 2*1013
a11 x1 + a12 x2 + a13 x3 + + a1n xn = b1
Operation Count x2 + a23
a22 x3 + + a2 n xn = b2
for k = 1:n-1
for i = k+1:n
(n-1)
x3 +
a33 + a3n xn = b3
factor = Aug(i,k)/Aug(k,k)
rows
Aug(i,k:nb) = Aug(i,k:nb)-
( n −1)
factor*Aug(k,k:nb) ann xn = bn( n −1)
end
end
n col.
Outer Loop Inner Loop Addition/Subtraction Multiplication/Division +1
k i flops flops f 21 = a21 / a11
f31 = a31 / a11
1 2, n (n − 1)(n) (n − 1)(n + 1) f 41 = a41 / a11
2 3, n (n − 2)(n − 1) (n − 2)(n) ...
k k + 1, n (n − k )(n − k + 1) (n − k )(n − k + 2)
n −1 n, n (1)(2) (1)(3)
n (n2 +n )/2 M/D
i(i-1) = (n3 –n )/3
i=1
n3/3+n2/2-5n/6 Back substitution: (n2 -n )/2 A/S
Diagonal f
f1 g1 Superdiagonal g x1 r1
e f2 g2 x r
2 2 2
e3 f3 g3 x3 r3
Subdiagonal e
=
ei fi gi
xi ri
en −1 f n −1 g n −1 xn −1 rn −1
en f n xn rn
(3)
e
2
f2
e3
g2
f3 g3
x r
2 2
x3 r3
Gauss Elimination …
=
(i) ei fi gi xi ri
f1 g1 r1
en −1 f n −1 g n −1 xn −1 rn −1
(2) - e2/f1* (1):
f 2' g2 r2' en f n xn rn
0 𝑒3 𝑓3 𝑔3 𝑟3
e e2
f = f 2 − 2 g1
' r2' = r2 − r1
2
f1 f1
x1 r1
(1)
f1 g1
(2) f 2 r
g2 2 2
x
(3) – e3/f2* (2) (3)
x3
… f3 g3
3
r
(i) – ei/fi-1* (i-1) (i)
x = f = f −
ek
g k −1
k k
i f k −1
k = 2,3, ,n
r = r − k r e
(n-1) – en-1/fn-2* (n-2) x
k k f k −1 k −1
n −1
(n) – en/fn-1*(n-1) xn
(1) f1 g1 r1
1 x
(2)
f 2 g2
x2 2
r
(3) f3
…
g3
3 x r3
ek
(i) = f k = f k − f g k −1
f i gi xi r i k −1
k = 2,3, ,n
r = r − k r e
k k f k −1 k −1
f n −1 g n −1 xn −1 rn −1
x
f n n rn
Tridiagonal Matrix
➢ Back substitution
→ x1 = (r1 -g1x2)/f1
f1 g1 x1 r1
0 f 2' g2 x r'
2 2
0 f3' g3 x3 r3'
=
0 fi ' gi
xi ri ' → xi = (ri -gixi+1)/fi
0 f n'−1 g n −1 xn −1 rn' −1 xn-1 = (rn-1 -gn-1xn)/fn-1
→
0 f n' xn rn' → xn = rn/fn
rn
xn =
fn
rk − g k xk +1
xk = k = n − 1, n − 2, ,3, 2,1
fk
Lecture 13
Last lecture:
Gauss elimination code
Operation count
Tridiagonal algorithm
This lecture:
1 0 0
Put “multiplying coefficients” to get L L = 1/ 3 1 0
2 / 3 0.0909 1
1 0 0 3 1 −1 3 1 −1
LU = 1/ 3 1 0 0 3.6667 1.3333 = 1 4 1 = A
2 / 3 0.0909 1 0 0 2.5455 2 1 2
Why?
3.4.1 L-U Decomposition based on Gaussian elimination
1 0 0 0 ... 0 0 0 1 0 0 0 ... 0 0
0 1 0 0 ... 0 0 1 0 1 0 0 ... 0 0
0 −𝑚3 1 0 ... 0 𝑚3 0 0 0 1 0 ... 0 0
𝑀2 = , 𝒎= , 𝒆2 = , 𝑀3 = , 𝒕= ,
0 −𝑚4 0 1 ... 0 𝑚4 0 0 0 −𝑡4 1 ... 0 𝑡4
... ... ... ... ... ... … … ... ... ... ... ... ... …
0 −𝑚𝑛 0 0 0 1 𝑚n 0 0 0 −𝑡n 0 0 1 𝑡n
• Mk = I - m𝑒𝑘𝑇 , where m = [0,…,0, mk+1,…,mn]T and ek is the kth column of the identity matrix.
• 𝑀𝑘−1 =I+ m 𝒆𝑇𝑘 , which means that Lk= 𝑀𝑘−1 is the same as Mk except that the signs of the multipliers are reversed. Why?
Mk 𝑀𝑘−1 = I- m𝑒𝑘𝑇 + m𝑒𝑘𝑇 - m 𝑒𝑘𝑇 m 𝑒𝑘𝑇 = I
• If Mj , j > k, is another elementary elimination matrix, with vector of multipliers t, (e.g. M3 = I - t𝑒3𝑇 ) then 0
Mk Mj = I - m𝑒𝑘𝑇 - t𝑒𝑗𝑇 + m 𝑒𝑘𝑇 t 𝑒𝑗𝑇 = I - m 𝑒𝑘𝑇 - t 𝑒𝑗𝑇 since 𝑒𝑘𝑇 t = 0 0
𝑚3
𝑒2𝑇 m = [0,1,0,…,0] 𝑚4 = 0
0
0
0 𝑚n
𝑒2𝑇 t = [0,1,0,…,0] • Thus, their product is essentially their “union."
−𝑡4 = 0
• Because they have the same form, a similar result
holds for the product of their inverses, LkLj .
−𝑡n
3.4.1 L-U Decomposition based on Gaussian elimination A=LU
1 0 0 0 ... 0 0 0 1 0 0 0 ... 0 0
0 1 0 0 ... 0 0 1 0 1 0 0 ... 0 0
0 −𝑚3 1 0 ... 0 𝑚3 0 0 0 1 0 ... 0 0
𝑀2 = , 𝒎= , 𝒆2 = , 𝑀3 = , 𝒕= ,
0 −𝑚4 0 1 ... 0 𝑚4 0 0 0 −𝑡4 1 ... 0 𝑡4
... ... ... ... ... ... … … ... ... ... ... ... ... …
0 −𝑚𝑛 0 0 0 1 𝑚n 0 0 0 −𝑡n 0 0 1 𝑡n
For A{x} = {b}, to reduce the 1st column multiply M1 on both sides
to reduce the 2nd column multiply M2 on both sides AGAIN
…
Mn-1 …M2M1A{x} = Mn-1 …M2M1 {b} = M{b}
After reduction is complete, LHS becomes U{x} with U=MA
U{x} =M{b}
M-1U{x} = {b}
M-1 is the L matrix we are looking for .
L= L1 L2…Ln-1
1 0 0 1 0 0 0 ... 0
𝑎21 /𝑎11 1 0 𝑎21 /𝑎11 1 0 0 ... 0
′ ′ ′ ′
𝑎 /𝑎 𝑎32 /𝑎22 1 𝑎 /𝑎 𝑎32 /𝑎22 1 0 ... 0
f1 = 31 11 , f2 = ′ ′ , f3 = ′′ ′′ … L= 31 11 ′ ′ ′′ ′′
𝑎41 /𝑎11 𝑎42 /𝑎22 𝑎43 /𝑎33 𝑎41 /𝑎11 𝑎42 /𝑎22 𝑎43 /𝑎33 1 ... 0
… … … ... ... ... ... ... ...
′ ′ ′′ ′′ ′ ′ ′′ ′′
𝑎𝑛1 /𝑎11 𝑎𝑛2 /𝑎22 𝑎𝑛3 /𝑎33 𝑎𝑛1 /𝑎11 𝑎42 /𝑎22 𝑎𝑛3 /𝑎33 … … 1
◊ Procedure: (you need to multiply L & U out to get cij, then compare each cij with aij in the original matrix A)
• First column in C gives the 1st column in L; it is easy to find:
l11 = a11, l21 = a21, l31 = a31, l41 = a41 li1 = ai1
• Now, the 1st row in C gives the 1st row in U as follows: l11 u12 = a12, l11 u13 = a13, l11 u14 = a14 u1j = a1j/ l11
• Now, the 2nd column in C gives the 2nd column in L:
3.4.2 Crout reduction
* Consider 0 2 1 ...1 1 0 0
A= 1 0 0 ...2 & let p=I= 0 1 0
3 0 1 ...3 0 0 1
* Interchange row 1 with row 3 (to avoid dividing by l11 =0) for A & p
3 0 1 0 0 1
A’= 1 0 0 p= 0 1 0 * Interchange row 2 with row 3
0 2 1 1 0 0 3 0 1 3 0 0 1 0 1/3 0 0 1
3 0 1 𝑙11 0 0 1 𝑢12 𝑢13 0 2 1 = 0 𝑙22 0 0 1 𝑢23 p= 1 0 0
1 0 0 = 𝑙 𝑙 0 0 1 𝑢 1 0 0 1 𝑙32 𝑙33 0 0 1 0 1 0
21 22 23
0 2 1 𝑙31 𝑙32 𝑙33 0 0 1 𝑙21 =0
𝑙11 =3 𝑙11 𝑢12 =0 𝑢12 =0 𝑙31 =1 𝑙21 𝑢12+𝑙22 =2 𝑙22 =2 − 𝑙21 𝑢12 =2
𝑙21 =1 𝑙11 𝑢13 =1 𝑢13 =1/3 𝑙21 𝑢13+𝑙22 𝑢23 =1 𝑢23 =(1-𝑙21 𝑢13)/𝑙22 =1/2
𝑙21 𝑢12+𝑙22 =0 𝑙22 =0 𝑙31 𝑢12+𝑙32 =0 𝑙32 =-𝑙31 𝑢12 =0
𝑙31 =0
𝑙21 𝑢13+𝑙22 𝑢23 =0 𝑢23 =-𝑙21 𝑢13 /𝑙22 Finally, 1 ∗ (1/3) +𝑙32 𝑢23 +𝑙33 =0 𝑙33 =-1/3
dividing by 𝑙22 =0
Pivoting in Crout reduction
* We can use permutation matrix p on
3 0 1 3 0 0 1 0 1/3 0 0 1 Gauss elimination with partial pivoting.
0 2 1 = 0 2 0 0 1 1/2 & p= 1 0 0 Ax = b
1 0 0 1 0 −1/3 0 0 1 0 1 0
pA x = LU x = p b
* Suppose b = [5, -1, -2]T is the RHS of Ax = b.
𝑥1 Matlab
0 2 1 5
1 0 0 𝑥2 = −1 >> A=[0 2 1;1 0 0;3 0 1]
3 0 1 𝑥3 −2 >> [L U P]=lu(A)
* Multiply final p on both sides of Ax = b, L= >> y=L\(P*b)
1.0000 0 0
y=
pA = LU 0 1.0000 0
0.3333 0 1.0000 -2.0000
0 0 1 5 −1 U= 5.0000
pb= 1 0 0 −1 = −2 = b’ 3.0000 0 1.0000 -0.3333
0 1 0 −2 5 0 2.0000 1.0000
0 0 -0.3333 >> x=U\y
* Now solving P= x=
0 0 1 -1.0000
3 0 0 1 0 1/3 𝑥1 −1 𝑥1 −1 1 0 0
2.0000
𝑥2 = 2 0 1 0
0 2 0 0 1 1/2 𝑥2 = −2 1.0000
1 0 −1/3 0 0 1 𝑥3 5 𝑥3 1
3.4.3 Evaluation of Determinant
* Determinant of a triangular matrix:
a11 a12 a13 a1n a22 a23 ... a2 n a33 ... a33
0 a22 a23 a2 n 0 a33 ... a3n
D= 0 a33 a3n = a11 * = a11 * a22 a3n = ... = a11*a22*a33…*ann
0
0
0 ann
ann
0 ann
= u11*u22*u33…*unn
x2 x2
Diamond=region of
solution uncertainty
x1 x’1 x”1 x1
Small change in the intercepts of the lines
Large change in x1 & x2
Inaccurate solution Ill-conditioned system
3.5 Condition Number and Error Analysis
Large change in x:
x - x* = (8.2, 13.6, 3.5, 2.1) T
10 7 8 7 32
7 23
5 6 5
Consider the following 4x4 system: A x = =b
8 6 10 9 x= 33
7 5 9 10 31
i.e. b** differs from b by (0.01, -0.01, 0.01, -0.01)T; || b - b** ||2 =0.02
Solve for x** from A x** = b** x** = (0.18, 2.36, 0.65, 1.21)T
0
◊ How does cond(A) affect solution accuracy?
0
1.01x + 0.99y = 1.98
-1 -1 0.99x + 1.01y = 2.02
-2 -2
-2 -1 0 x 1 2 3 4 -2 -1 0 x 1 2 3 4
3.5.3 Error analysis and condition number
* Eqn. A x = b; (x denotes the exact solution) (4) & (5) || b || / || A || ≤ || x || ≤ || A-1 || || b || (6)
Note: all x values on the RHS are from the mth iteration
𝑎12 𝑎13 𝑎14 𝑏1
Convergence consideration 0 − − −
𝑎11 𝑎11 𝑎11 𝑎11
𝑎11 𝑥1 + 𝑎12 𝑥2 + 𝑎13 𝑥3 + 𝑎14 𝑥4 = 𝑏1
𝑎21 𝑎23 𝑎24 𝑏2
𝑎21 𝑥1 + 𝑎22 𝑥2 + 𝑎23 𝑥3 + 𝑎24 𝑥4 = 𝑏2 − 0 − −
𝑎31 𝑥1 + 𝑎32 𝑥2 + 𝑎33 𝑥3 + 𝑎34 𝑥4 = 𝑏3 𝑎22 𝑎22 𝑎22 𝑎
𝐶= 𝑎31 𝑎32 𝑎34 , d = 22
𝑎41 𝑥1 + 𝑎42 𝑥2 + 𝑎43 𝑥3 + 𝑎44 𝑥4 = 𝑏4 𝑏3
− − 0 −
𝑎33 𝑎33 𝑎33 𝑎33
Rewrite the matrix equation 𝑎41 𝑎42 𝑎43
− − − 0 𝑏4
𝑎12 𝑎13 𝑎14 𝑏1 𝑎44 𝑎44 𝑎44
𝑥1 = − 𝑥 − 𝑥 − 𝑥 + 𝑎44
𝑎11 2 𝑎11 3 𝑎11 4 𝑎11
𝑎21 𝑎23 𝑎24 𝑏2 For system of equations, convergence requirement on C (not A)
𝑥2 = − 𝑥 − 𝑥 − 𝑥 +
𝑎22 1 𝑎22 3 𝑎22 4 𝑎22
𝑎31 𝑎32 𝑎34 𝑏3 𝜆𝑖 ≤ 1, 𝜆 = 𝑒𝑖𝑔(𝐶 )
𝑥3 = − 𝑥1 − 𝑥2 − 𝑥4 +
𝑎33 𝑎33 𝑎33 𝑎33
𝑎41 𝑎42 𝑎43 𝑏4 Why?
𝑥4 = − 𝑥1 − 𝑥2 − 𝑥3 +
𝑎44 𝑎44 𝑎44 𝑎44
𝑥 (𝑚+1) = 𝐶𝑥 (𝑚) + 𝑑; 𝐶ii = 0
Convergence consideration
𝑥 (𝑚+1) = 𝐶𝑥 (𝑚) + 𝑑
𝜆𝑖 of 𝐶 is difficult to find.
(𝑚+1) (𝑚)
𝑥𝑒𝑥𝑎𝑐𝑡 = 𝐶𝑥𝑒𝑥𝑎𝑐𝑡 + 𝑑 Diagonal dominance is much easier to check
Subtract
𝑒 (𝑚+1) = 𝐶𝑒 (𝑚)
= 𝐶 2 𝑒 (𝑚−1) = ⋯
= 𝐶 𝑚+1 𝑒 (0)
Eigenvalue decomposition: C = P D P-1
𝜆1 0 0 … 0
0 𝜆2 0 … 0
D= 0 0 𝜆3 … 0
… … … ... …
0 0 0 ... 𝜆𝑛
1
𝑥1 = 1.833333 + 0.3333 * 0 - 0.166667 * 0 = 1.833333
1
𝑥2 = 0.714286 + 0.285714 * 1.833333 - 0.285714 * 0 Necessary and sufficient condition -- the magnitude of the
= 1.238095 largest eigenvalue of C (not A) is less than 1.
1 Fortunately, many engineering problems of practical
𝑥3 = 0.2 + 0.2*1.833333 + 0.4*1.238095 = 1.061905
importance satisfy this requirement.
3.6.4 Relaxation method
𝒊−𝟏 𝒏
General algorithm description for Ax = b: 1 (𝑚+1) − (𝑚)
𝒏
(𝑚+1)
𝑥𝑖 =𝑥𝑖
(𝑚)
+ a [bi - aij𝑥𝑗 aij𝑥𝑗 (𝑚)
-a𝑖𝑖𝑥𝑖 ]
ii
aijxj = bi 𝒋=𝟏 𝒋=𝒊+𝟏
𝒋=𝟏 (𝑚)
=𝑥𝑖 + [ xi( m +1) − xi( m ) ]
𝒊−𝟏 𝒏
aii xi = bi - aijxj − aijxj Introduce relaxation factor w:
𝒋=𝟏 𝒋=𝒊+𝟏
𝒏
𝑥𝑖
(𝑚+1) (𝑚)
=𝑥𝑗 + w[ xi( m +1) − xi( m ) ]
𝒊−𝟏
Jacobi: 𝑥 (𝑚+1) = 1 [b - a 𝑥 (𝑚) − aij𝑥𝑗(𝑚) ]
𝑖 a i ii
ij 𝑗 w >2: solution diverges
𝒋=𝟏 𝒋=𝒊+𝟏
𝒊−𝟏
𝒏 1<w <2: over-relaxation
(𝑚)
G-S: (𝑚+1) 1 (𝑚+1) − aij𝑥 ]
𝑥𝑖 = a [bi - aij𝑥𝑗 𝑗 w<1: under-relaxation
ii 𝒋=𝒊+𝟏
𝒋=𝟏
𝒏
𝒊−𝟏
(𝑚)
( m +1) 1 (𝑚+1) − aij𝑥 ]
Let x = [bi - aij𝑥𝑗 𝑗
i aii 𝒋=𝒊+𝟏
𝒋=𝟏
(𝑚)
Add & subtract 𝑥𝑖 to G-S scheme:
−4 1 1 1 𝑥1 1
1 −4 1 1 𝑥2 1
Example: 𝑥3 = 1
1 1 −4 1
1 1 1 −4 𝑥4 1
w Number of iteration
1.0 24
1.1 18
1.2 13
1.3 11
1.4 14
1.5 18
1.6 24
1.7 35
1.8 55
1.9 >100
3.7 System of Nonlinear Equations
Circle x2 + y2 = r2
◊ Consider a 2-equation system to start with:
f1(x1, x2) = 0
f1(x,y)=0
f2(x1, x2) = 0 f2(x,y)=0
(m) (m)
J(x(m)) x(m+1) = J(x ) x - f(x )
(m)
Eqn. (*)
h ( x, y , z ) = x − 3 y 2 + z 2 = 0
3 1, 2 3
f ( x x , x ) = x1 − 3 x2
2
+ x3 =0
2
Practical remedy:
after every 5 iterations for xk
Suppose it takes a total of n=15 iterations using this method.
x2 x2
Diamond=region of
solution uncertainty
x1 x’1 x”1 x1
Small change in the intercepts of the lines
Large change in x1 & x2
Inaccurate solution Ill-conditioned system
3.5.1 Ill-conditioned system
Large change in x:
xexact - x* = (8.2, 13.6, 3.5, 2.1) T
10 7 8 7 32
7 23
5 6 5
Consider the following 4x4 system: A x = =b
8 6 10 9 x = 33
7 5 9 10 31
i.e. b** differs from b by (0.01, -0.01, 0.01, -0.01)T; || b - b** ||2 =0.02
Solve for x** from A x** = b** x** = (0.18, 2.36, 0.65, 1.21)T
10 7 8 7
7 5 6 5
25 −41 10 −6
, −41 68 −17 10
A-1 =
For A = 8 6 10 9 10 −17 5 −3
7 5 9 10 −6 10 −3 2
* Eqn. A x = b; (x denotes the exact solution) (4) & (5) || b || / || A || ≤ || x || ≤ || A-1 || || b || (6)
* Relative error of the solution: || e || / || x || = ? which means that the solution x should be close to 0.
* If Cond(A) = O(1), small round-off error
* Ax=b || b || ≤ || A || || x || (4)
small relative error in solution || e || / || x ||.
* x = A-1 b || x || ≤ || A-1 || || b || (5)
1 |𝑟| |𝑒| |𝑟|
≤ ≤ 𝑐𝑜𝑛𝑑(𝐴) (7’)
𝑐𝑜𝑛𝑑(𝐴) | 𝑏 | |𝑥| |𝑏|
* If Cond(A) is large, say O(105), the relative error in solution, || e || / || x ||, can be of O(10-2).
Further computation using x suffers significant loss of accuracy.
* If Cond(A) is of O(105) or O(106), one remedy is to use double precision to obtain x.
However, even double precision is not enough if cond(A) = O(1014).
* Cond(A) is a very important measure of the matrix system.
3.6 Iterative Method
3.6.1 When do we use the iterative method?
Interchange Row 2 with Row 3:
* A sparse matrix with a lot of zero elements.
6 −2 1 𝑥1 11
Reduction step in Gauss elimination method reduces 0 to 0. −2 7 2 𝑥2 = 5
Wasteful 1 2 −5 𝑥3 −1
Iterative method w/o touching those 0 elements is preferred. Diagonal dominance now achieved
* Diagonal dominance must be achieved before starting
𝒏 Divide the ith row by aii,
| aii |> |aij | express xi as a function of other x's for i=1, 2, 3
𝒋=𝟏,𝒋≠𝒊
11 2 1
Consider 6 −2 1 𝑥1 11 x1 = + x2 - x3
6 6 6
1 2 −5 𝑥2 = −1
5 2 2
−2 7 2 𝑥3 5 x2 = 7 + 7 x1 - 7 x3
1 1 2
Row 2: 2<1+5=6 x3 = 5 + 5 x1 + 5 x2
Diagonal dominance
Row 3: 2<2+7=8 not achieved
3.6.2 Jacobi method
Note: all x values on the RHS are from the mth iteration
𝑎12 𝑎13 𝑎14 𝑏1
Convergence consideration 0 − − −
𝑎11 𝑎11 𝑎11 𝑎11
𝑎11 𝑥1 + 𝑎12 𝑥2 + 𝑎13 𝑥3 + 𝑎14 𝑥4 = 𝑏1
𝑎21 𝑎23 𝑎24 𝑏2
𝑎21 𝑥1 + 𝑎22 𝑥2 + 𝑎23 𝑥3 + 𝑎24 𝑥4 = 𝑏2 − 0 − −
𝑎31 𝑥1 + 𝑎32 𝑥2 + 𝑎33 𝑥3 + 𝑎34 𝑥4 = 𝑏3 𝑎22 𝑎22 𝑎22 𝑎
𝐶= 𝑎31 𝑎32 𝑎34 , d = 22
𝑎41 𝑥1 + 𝑎42 𝑥2 + 𝑎43 𝑥3 + 𝑎44 𝑥4 = 𝑏4 𝑏3
− − 0 −
𝑎33 𝑎33 𝑎33 𝑎33
Rewrite the matrix equation 𝑎41 𝑎42 𝑎43
− − − 0 𝑏4
𝑎12 𝑎13 𝑎14 𝑏1 𝑎44 𝑎44 𝑎44
𝑥1 = − 𝑥 − 𝑥 − 𝑥 + 𝑎44
𝑎11 2 𝑎11 3 𝑎11 4 𝑎11
𝑎21 𝑎23 𝑎24 𝑏2 For system of equations, convergence requirement on C (not A)
𝑥2 = − 𝑥 − 𝑥 − 𝑥 +
𝑎22 1 𝑎22 3 𝑎22 4 𝑎22
𝑎31 𝑎32 𝑎34 𝑏3 𝜆𝑖 ≤ 1, 𝜆 = 𝑒𝑖𝑔(𝐶 )
𝑥3 = − 𝑥1 − 𝑥2 − 𝑥4 +
𝑎33 𝑎33 𝑎33 𝑎33
Why?
𝑎41 𝑎42 𝑎43 𝑏4
𝑥4 = − 𝑥1 − 𝑥2 − 𝑥3 +
𝑎44 𝑎44 𝑎44 𝑎44
𝑥 (𝑚+1) = 𝐶𝑥 (𝑚) + 𝑑; 𝐶ii = 0
Convergence consideration
𝑥 (𝑚+1) = 𝐶𝑥 (𝑚) + 𝑑
𝜆𝑖 of 𝐶 is difficult to find.
(𝑚+1) (𝑚)
𝑥𝑒𝑥𝑎𝑐𝑡 = 𝐶𝑥𝑒𝑥𝑎𝑐𝑡 + 𝑑 Diagonal dominance is much easier to check
Subtract
𝑒 (𝑚+1) = 𝐶𝑒 (𝑚)
= 𝐶 2 𝑒 (𝑚−1) = ⋯
= 𝐶 𝑚+1 𝑒 (0)
Eigenvalue decomposition: C = P D P-1
𝜆1 0 0 … 0
0 𝜆2 0 … 0
D= 0 0 𝜆3 … 0
… … … ... …
0 0 0 ... 𝜆𝑛
Interpolation
3.6.3 Gauss-Seidel point iterative method
1
𝑥1 = 1.833333 + 0.3333 * 0 - 0.166667 * 0 = 1.833333
1
𝑥2 = 0.714286 + 0.285714 * 1.833333 - 0.285714 * 0 Necessary and sufficient condition -- the magnitude of the
largest eigenvalue of C (not A) is less than 1.
= 1.238095
Fortunately, many engineering problems of practical
1
𝑥3 = 0.2 + 0.2*1.833333 + 0.4*1.238095 = 1.061905
importance satisfy this requirement.
3.6.4 Relaxation method
aijxj = bi 𝒊−𝟏 𝒏
(𝑚+1) (𝑚) 1 (𝑚+1) − a 𝑥 (𝑚) (𝑚)
𝒋=𝟏 𝑥𝑖 =𝑥𝑖 + a [bi - aij𝑥𝑗 ij 𝑗 -a𝑖𝑖𝑥𝑖 ]
𝒏 ii 𝒋=𝒊+𝟏
𝒊−𝟏 𝒋=𝟏
aii xi = bi - aijxj − aijxj (𝑚)
=𝑥𝑖 + [ xi( m +1) − xi( m ) ]
𝒋=𝟏 𝒋=𝒊+𝟏
(𝑚)
Add & subtract 𝑥𝑖 to G-S scheme:
−4 1 1 1 𝑥1 1
1 −4 1 1 𝑥2 1
Example: 𝑥3 = 1
1 1 −4 1
1 1 1 −4 𝑥4 1
w Number of iteration
1.0 24
1.1 18
1.2 13
1.3 11
1.4 14
1.5 18
1.6 24
1.7 35
1.8 55
1.9 >100
3.7 System of Nonlinear Equations
Circle x2 + y2 = r2
◊ Consider a 2-equation system to start with:
f1(x1, x2) = 0
f1(x,y)=0
f2(x1, x2) = 0 f2(x,y)=0
Practical remedy:
Suppose it takes a total of n=15 iterations using this method.
1 0 0 1 2 3 1 0 0 0 0 0 1 2 3
0 0 2 4 5 6 = 0 0 0 + 0 0 2 4 5 6
i)
0 0 0 7 8 9 0 0 0 0 0 0 7 8 9
1 2 3 0 0 0 1 2 3
+ 14 16 18 = 14 16 18
= 0 0 0
0 0 0 0 0 0 0 0 0
1 0 2 1 2 3 1 0 0 0 0 2 1 2 3
0 0 0 4 5 6 = 0 0 0 + 0 0 0 4 5 6
ii)
0 0 0 7 8 9 0 0 0 0 0 0 7 8 9
0 0 1 1 2 3 7 8 9
1 0 0 4 5 6 = 1 2 3 From the left these
iii) matrices permute rows
0 1 0 7 8 9 4 5 6
1 2 3 0 0 1 3 1 2
4 5 6 1 0 0 = 6 4 5 From the right these
iv) matrices permute columns
7 8 9 0 1 0 9 7 8
Example 2 Matrix operation – trigonometric function of matrix
The trigonometric functions can be extended to matrices! For instance, the
cosine of a square matrix A is given by
( −1)n 2 n 1 1 1
cos A = A = I − A2 + A4 − A6 + L .
n =0 (2n )! 2! 4! 6!
1 0
If = , find the value of the determinant of cos .
1 2
Solution:
1 0 1 0 4 1 0
* Note: = => 2 = , = 2 4 ,
3(1 + 2 ) 2
2
1 2 3 2
1 0 8 1 0
6 = 2 4 6 , = 8 …
3(1 + 2 + 2 ) 2
2 4 6
3(1 + 2 + 2 + 2 ) 2
1 0
2n = 2 4
3(1 + 2 + 2 ... + 2
2n − 2
) 2 2n
n
1 2 1 4 1 6 1 8 1
Thus cos = I − + − + + ... + ( −1) 2n
2 4! 6! 8! (2n)!
1 1 n
1
1 − + + (−1) + ... 0
=
2! 4! (2n)!
n 2n
1 2 1 4 2
c21 1 − 2 + 2 + (−1) + ...
2! 4! (2n)!
cos(1) 0
= .
c21 cos(2)
Solution:
• First we note that A is almost like an identity matrix. In order to get to A2005,
we try the first few powers to have a better understanding.
0 0 0 0 1 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 1 0 0
1 0 0 0 0 0 2 2 0 0 0 0 1 0
• A 2 = AA = 4
, A = A A =
0 1 0 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0 0 0
& A6 = A2 A4 = I
Thus, A2005= A2004+1 = (A6)334+1 = IA = A
Hence the third row is: (0 1 0 0 0 0).
Example 4 Matrix operation – rotation of axes.
1 3
− −
If A = 2 2 , what is A12 ?
3 −
1
2 2
Solution 1:
Note: A3 = I
(you can verify this by simply multiplying A three times)
Thus, A12 = (A3)4 = I4 = I.
Solution 2:
cos − sin
A= with = 120 = 2/3 in the problem.
cos
We note:
sin
Thus, A u = rotation of u vector by 120 counter-clockwise.
(You should have seen this concept in Pre-calculus.)
Thus, A12 u = rotation of u vector by 12x120 =1440 = 4 x 360
counter-clockwise
=u
It means that A12 must be an identity matrix I.
Example 5 Norm of an inverse matrix
Prove or give a counterexample: if A is a non-singular matrix, then
-1 -1
|| A || = || A ||
-1 -1 -1
Solution: Note: || A A || = || I || =1 and || AA || || A || || A ||
-1 -1
|| A || 1/ ||A || = || A ||
-1 -1
Thus, in general, || A || || A || & the equality holds only for some
special cases.
* Reduction:
No need to work on row 2 since a21 = 0 already.
4 2 − 1 − 6.3 − −r1
r3 − r1 / 4 r3 : A = 0 3 4 14.8 − −r 2
0 − 1.5 5.25 15.075 − −r 3
4 2 − 1 − 6.3 − −r1
r3 + r 2 / 2 => A = 0 3 4 14.8 − −r 2
0 0 7.25 22.475 − −r 3
* Back substitution:
z = 22.475/7.25 = 3.1
y = (14.8-4*3.1)/3 = 0.8
x = (-6.3-2*0.8+3.1)/4 = -1.2
=> (x, y, z) = (-1.2, 0.8, 3.1)
Example 8 Solving tri-diagonal system
6.4 3.2 0 0 − 1.6
3.2 − 1.6 4.8 0 32
For an augmented matrix A =
0 4.8 − 9.6 7.2 − 78
0 0 7.2 4.8 20.4
Find the solution.
Solution:
s1 0 0
A = USV= U 0 s2 0 V
0 0 s3
Solution: (We will use this opportunity to illustrate the use of Matlab, too).
% Define the matrix:
» A=[2 2 -4; 2 -1 -2;4 2 -6];
% Compute the eigenvalues:
» p=eig(A)
ans =
-1.0000
-2.0000
-2.0000
*(NOTE: we have a repeated eigenvalue of -2)
% Compute three eigenvectors:
» v1=null(A-p(1)*eye(3),'r')
v1 =
1.0000
0.5000
1.0000
» v2=null(A-p(2)*eye(3),'r')
v2 =
-0.5000 1.0000
1.0000 0
0 1.0000
% Form a matrix W based on eigenvectors:
>> W=[v1 v2]
W =
1.0000 -0.5000 1.0000
0.5000 1.0000 0
1.0000 0 1.0000
% Find the inverse of W:
» C=inv(W)
C =
4 2 -4
-2 0 2
-4 -2 5
-1
% Compute W AW:
» D=inv(W)*A*W
D =
-1 0 0
0 -2 0
0 0 -2
* We note that the diagonal elements in D are the eigenvalues:
1 0 0
D = 0 2 0
0 0 3
where 3 =2 in this particular case.
* Generalize:
1 0 ... 0
0 ... 0
W AW=D=
-1 2
... ... ... ...
0 0 0 n
Hence, W(W-1 A W) W-1 = W (D) W-1
That is, A = W (D) W-1
* For the present problem, we thus have
1 − 0.5 1 − 1 0 0 4 2 − 4
A = W (D) W-1 = 0.5 1 1 0 − 2 0 − 2 0 2
1 0 1 0 0 − 2 − 4 − 2 5
k 0 0
...
1
… Ak= W Dk W-1 = W
0 k2 ... 0 W-1
... ... ... ...
0 0 0 kn
which allows one to compute exp(A) in terms of Taylor series expansion.
* This eigenvalue decomposition is also quite useful in solving system of first
order linear ordinary differential equations.
Example 10 Study on ill-conditioned Hilbert matrix
Consider the Hilbert matrix (using 5x5 as an example).
1 1/ 2 1/ 3 1/ 4 1 / 5
1 / 2 1/ 3 1/ 4 1/ 5 1 / 6
H 5 = 1 / 3 1/ 4 1/ 5 1/ 6 1 / 7
1 / 4 1/ 5 1/ 6 1/ 7 1 / 8
1 / 5 1/ 6 1/ 7 1/ 8 1 / 9
1 j + j −2
The element Bij = 1/(i+j-1) comes from the integral Bij = 0 x dx
1.E+08 Cond
1.E+07
1.E+06
1.E+05
1.E+04
1.E+03 Cond(H(n))
1.E+02
1.E+01
1.E+00
1 2 3 4 5 6 n
determinant
1.E+00
1.E-02 det(H(n))
1.E-04
1.E-06
1.E-08
1.E-10
1.E-12
1.E-14
1.E-16
1.E-18
1 2 3 4 5 6 n
Example 11 Study on ill-conditioned Vandermonde matrix
Let x = (x0, x1, x2, x3, x4)T = (2, 3, 4, 5, 6)T
The 5x5 Vandermonde matrix is
1 x0 x02 x03 x04
1 3 9 27 81
12 4 8 16
1
V5= 1
x1 x12
x 22
x13
x 23
x14
x 24 =
1 4 16 64 256
1 5 25 125 625
x2
1 x34
1
x3
x4
x32
x 42
x33
x 43
x 44
1 6 36 216 1296
Find its determinant, condition number, eigenvalues, and inverse matrix.
Solution: (using Matlab)
...(input the matrix V5 in Matlab here)…
* From the magnitude of the condition number, we can see that it will be
difficult to get accurate solution to the system of equations with V5 as the
|| e ||
coefficient matrix. The relative error in the solution, , can be as high as
|| x ||
-2
O(10 ) on a single precision machine if the constant vector b is such that
|| b || ~ O(1). This is one of the major limitations on using the method of
undetermined coefficient to interpolate the data.
* We can also see that the ratio, max(i)/min(i), of the eigenvalue is
1409.85304217870 / 0.01239938420 = 113703.473
Results:
n x1 x2 x3 sum(e(i))
0 0 0 0
1 1.8333 0.7143 0.2 2.74760
2 2.03803619 1.18093381 0.85238 1.32375
3 2.084813493 1.053041973 1.0799808 0.40227
4 2.004246097 1.001380711 1.0381795 0.17403
5 1.99399567 0.99030523 1.0014015 0.05810
6 1.996435103 0.997884153 0.9949212 0.01650
7 2.00004142 1.000432514 0.9984407 0.00967
8 2.000304095 1.000457331 1.0001813 0.00203
9 2.000022207 1.000035086 1.0002438 0.00077
10 1.999871061 0.999936705 1.0000185 0.00047
11 1.999875824 0.999957884 0.9999489 9.6E-05
12 1.999894482 0.999979124 0.9999583 4.9E-05
13 1.99989999 0.999981762 0.9999705 2E-05
n n −1 n n −1 n n −1
sum(e(i))=| | x1 − x1 | + | x2 − x2 | + | x3 − x3 |
Computation stops here since the roundoff error in coefficients are around 5E-5.
1.E+01
sum |e(i)|
1.E+00
1.E-01
1.E-02
1.E-03
1.E-04
1.E-05
1.E-06
1.E-07
1.E-08
1.E-09
0 5 10 15 20 n
Example 13 Gauss-Seidel method for system of equations (on Excel sheet)
Start from the initial guess of x(0) = (0, 0, 0)T, implementing the following
Jacobi iterative procedure on the Excel spreadsheet.
Results:
n x1 x2 x3 sum |e(i)|
0 0 0 0
1 1.8333 1.23807381 1.0618895 4.13326
2 2.068933017 1.002012326 1.0145915 0.51899
3 1.998138300 0.995299311 0.9977474 0.09435
4 1.998708771 1.000274668 0.9998516 0.00765
5 2.000016282 1.000047043 1.0000221 0.00171
6 1.999912000 0.999968552 0.9999698 0.00024
7 1.999894549 0.999978495 0.9999703 2.8E-05
Comparison of convergence behavior between Jacobi method and
Gauss-Seidel method:
⎯ n +1 ⎯
xn+1 = ( x1
n n
+ x3 + x4 -1)/4; x2n +1 = xn2 + (xn+1 - xn2) =>
2 2
⎯ ⎯
xn+1 = ( x1
n +1 n +1
+ x2
n
+ x4 -1)/4; x3n +1 = xn + (xn+1 - xn) =>
3 3 3 3
⎯ n +1 n +1 n +1 ⎯
xn+1
= ( x1 + x2 + x3 -1)/4; x4n +1 =
n
x4 + (x n+1 n
- x4)
4 4
Excel Formula:
n x1 x2 x3 x4
0 0 0 0 0
=C2+ww*((-1+D2 =D2+ww*((-1+E2 =E2+ww*((-1+F2 =F2+ww*((-1+C3
1 +E2+F2)/4-C2) +F2+C3)/4-D2) +C3+D3)/4-E2) +D3+E3)/4-F2)
=C3+ww*((-1+D3 =D3+ww*((-1+E3 =E3+ww*((-1+F3 =F3+ww*((-1+C4
2 +E3+F3)/4-C3) +F3+C4)/4-D3) +C4+D4)/4-E3) +D4+E4)/4-F3)
=C4+ww*((-1+D4 =D4+ww*((-1+E4 =E4+ww*((-1+F4 =F4+ww*((-1+C5
3 +E4+F4)/4-C4) +F4+C5)/4-D4) +C5+D5)/4-E4) +D5+E5)/4-F4)
=C5+ww*((-1+D5 =D5+ww*((-1+E5 =E5+ww*((-1+F5 =F5+ww*((-1+C6
4 +E5+F5)/4-C5) +F5+C6)/4-D5) +C6+D6)/4-E5) +D6+E6)/4-F5)
Screen shot: (ww=omega is defined on cell A4; a value of 1.25 is specified)