Sei sulla pagina 1di 40

Civil Engineering Informatics Program

CEI SC-I 300


Scientific Computing I
Programming Numerical Methods

Prof. Dr. Nayer El-Esnawy


Head of Department and Professor of Structural Engineering

Spring 2015

Numerical Methods A-5

Lecture Agenda

1. Numerical Integration: Multiple Integrals

2. Numerical Differentiation & Differential Equations

3. Standard Eigenvalue Problem

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


Numerical Methods A-5

Lecture Agenda

1. Numerical Integration: Multiple Integrals

2. Numerical Differentiation & Differential Equations

3. Standard Eigenvalue Problem

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

1. Numerical Integration: Multiple Integrals

How to Numerically Integrate Multiple Integrals?


d b
I= ∫∫c a
f ( x, y ) dx dy
I = Volume bounded by curve f(x,y)
from “a” to “b” in x-direction and
from “c” to “d” in y-direction

Double integration can be executed


numerically in TWO steps:
b
1. I * ( y ) = ∫a f ( x , y ) dx
d
2. I = ∫c I * ( y ) dy

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


1. Numerical Integration: Multiple Integrals

How to Numerically Integrate Multiple Integrals?


b
1. I * ( y ) = ∫a f ( x , y ) dx
For each discrete value of yk, calculate
corresponding discrete value of integral
by one of numerical integration methods
b
I * (1) = I * ( y1 ) = ∫a f ( x , y1 ) dx
b
I * ( 2 ) = I * ( y 2 ) = ∫a f ( x , y 2 ) dx
:
:
b
I * ( N ) = I * ( y N ) = ∫a f ( x , y N ) dx

{ I *} = { I * (1), I * ( 2 ), K , I * ( N )}
{ y } = { y1 , y 2 , K, y N }
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

1. Numerical Integration: Multiple Integrals

How to Numerically Integrate Multiple Integrals?


d
2. I = ∫c I * ( y ) dy
Perform this integration using discrete
values of vectors {y} and {I *}

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


1. Numerical Integration: Multiple Integrals

How to Numerically Integrate Multiple Integrals?


Example
The measured temperatures of a heated
rectangular plate of 8×6 m are as shown.
Determine average temperature of plate 3 m

T avg = ⎛⎜
1 ⎞ 6 8
⎟ × ∫ ∫ T ( x , y ) dx dy 3m
⎝ area ⎠ 0 0

4m 4m

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

1. Numerical Integration: Multiple Integrals

How to Numerically Integrate Multiple Integrals?


Example
The measured temperatures of a heated
rectangular plate of 8×6 m are as shown.
Determine average temperature of plate 3 m

T avg = ⎛⎜
1 ⎞ 6 8
⎟ × ∫ ∫ T ( x , y ) dx dy 3m
⎝ area ⎠ 0 0

4m 4m

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


1. Numerical Integration: Multiple Integrals

How to Numerically Integrate Multiple Integrals?


Example
6 8 y(3)=6 I *(3)
I = ∫0 ∫0 T ( x , y ) dx dy
3m
6
I = ∫0 I * dy y(2)=3 I *(2)
3m
8
I * = ∫0 T ( x , y ) dx y(1)=0 I *(1)
(to be evaluated for each 4m 4m
discrete value of y) x=0 x=4 x=8
>> Istar(1)=trapz([0,4,8],[72,64,24]);
>> Istar(2)=trapz([0,4,8],[54,70,54]);
>> Istar(3)=trapz([0,4,8],[0,40,48]);
>> Istar
Istar =
448 496 256

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

1. Numerical Integration: Multiple Integrals

How to Numerically Integrate Multiple Integrals?


Example
6 8 y(3)=6 I *(3)
I = ∫0 ∫0 T ( x , y ) dx dy
3m
6
I = ∫0 I * dy y(2)=3 I *(2)
3m
8
I * = ∫0 T ( x , y ) dx y(1)=0 I *(1)
(to be evaluated for each 4m 4m
discrete value of y)
>> intval=trapz([0,3,6],Istar])
intval =
2544

>> Tavg = intval/(8*6)


Tavg =
53

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


1. Numerical Integration: Multiple Integrals

How to Do Numerical Integration by MATLAB?


5. dblquad(func, xmin, xmax, ymin, ymax)
- Function to be integrated must be known
The temperature of a heated rectangular 3m
plate of 8×6 m is calculated using
T ( x , y ) = 2 x y + 2 x − x 2 − 2 y 2 + 72 3m

Determine average temperature of plate


4m 4m

>> funT=@(x,y) 2*x.*y + 2*x - x.*x – 2*y.^2 + 72


funT =
@(x,y)2*x.*y+2*x-x.*x-2*y.^2+72
>> valint = dblquad(funT,0,8,0,6)
valint =
2816

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

Numerical Methods A-5

Lecture Agenda

1. Numerical Integration: Multiple Integrals

2. Numerical Differentiation & Differential Equations

3. Standard Eigenvalue Problem

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


2. Numerical Differentiation & Differential Equations

What is Meant By Numerical Differentiation?


It is the estimation of the derivatives (slope, curvature, etc.) of a function
by using the function values at only a set of discrete points
A common mathematical definition for
the first derivative of the function f(x)
at point “x” is as follows:
df f(x + dx) − f(x - dx)
= lim
dx dx → 0 2 dx
Thus, a practical finite approximation
for the first derivative of the function
f(x) at point “x” is as follows:

∆f f(x + ∆x) − f(x - ∆x) df


= =
∆x 2 ∆x dx
A smaller step ∆x (or h) results in a smaller error
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

What is a Finite Difference? h h


m ate
xi
df f(x + h) − f(x − h) x pro dx
@x: = e p
A df /
dx 2h Tru x x+h
d
df /
h = constant spacing between x-h
discrete points

df f(x i +1 ) − f(x i −1 )
@xi : = h h
dx 2h m ate
xi
xi pro dx
df f i +1 − f i −1 e p
A df /
@xi : = Tru x xi+1
dx 2h d
df / (xi+h)
xi-1
df − 0.5 f i −1 + 0.5 f i +1 (xi-h)
@xi : =
dx h
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
2. Numerical Differentiation & Differential Equations

Finite Difference Methods


Basic philosophy of finite difference methods is to represent derivatives of
problem (governing differential equations and boundary conditions) by the
approximate finite difference expressions in terms of the selected state
variable (displacements).
The finite difference expressions are evaluated at equally-spaced discrete
points selected inside the domain of analysis

This finite-difference discretization lead to a set of algebraic linear


equations that can be solved for the values of the state variables at the
equally-spaced discrete points.

There are several finite-difference methods:


1. Forward finite-difference (accuracy of 1st order)
2. Backward finite-difference (accuracy of 1st order)
3. Central finite-difference (accuracy of 2nd order)

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Finite Difference Methods


1. Forward Finite Difference at point (k)
Uses values of function at point (k) and following points (k+1), (k+2), etc
f(x) ve
ivati
de r
e
Tr
u Finite
ppr o ximation
A

df f k +1 − f k
@xk : =
dx h

h
x
xk−1 xk xk+1
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
2. Numerical Differentiation & Differential Equations

Finite Difference Methods


2. Backward Finite Difference at point (k)
Uses values of function at point (k) and preceding points (k – 1), (k – 2),etc
f(x) ve
ivati
de r
ue
Tr

n
df f k − f k −1

io
xi e
ro nit =
at
@xk :
m
pp Fi
dx h
A

h
x
xk−1 xk xk+1
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Finite Difference Methods


3. Central Finite Difference at point (k)
Uses values of function at point (i) and following points (k+1), (k+2), etc
and preceding points (k – 1), (k – 2), etc
f(x) i ve
r ivat
e de
u
Tr

nite tion df f k +1 − f k −1
i
F ima @xk : =
pr
o x dx 2h
Ap
2h
x
xk−1 xk xk+1
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
2. Numerical Differentiation & Differential Equations

Finite Difference Methods Forward df f k +1 − f k


Difference @ x k : =
Summary of First Derivative dx h
df/dx Backward df f k − f k −1
Difference @ x k : =
dx h
f(x) Central df f k +1 − f k −1
@ x : =
f ′( x ) Difference k
dx 2h

x
k-2 k-1 k k+1 k+2
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Accuracy and Truncation Errors


⎧ f ( x k +1 ) − f ( x k ) h
⎪ forward : f ′ ( x k ) = − f ′′ ( ξ 1 ) O(h)
⎪ h 2
⎪ f ( x k ) − f ( x k −1 ) h
⎨ backward : f ′ ( x k ) = + f ′′ ( ξ 2 ) O(h)
⎪ h 2
⎪ f ( x k +1 ) − f ( x k −1 ) h 2
′ f ′′′ ( ξ 3 ) O(h 2 )
⎪ central : f ( x k ) = 2h

6

Limitations of Forward and Backward Differences


1. They represent one-sided finite difference.
2. Error of the forward and the backward FD expressions is of the first order
O(h). Thus, they are less accurate than the central expressions.
3. They can be used in conjunction with the central finite difference to
handle boundary conditions at points near boundary, if phantom
points cannot be used.
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
2. Numerical Differentiation & Differential Equations

Central Finite Difference Expressions for 1D Domains


Second Derivative Using Taylor Series Expansion
⎧ h2 h3 h4
⎪⎪ f ( x i + 1 ) = f ( x i ) + hf ′( x i ) + f ′′( x i ) + f ′′′( x i ) + f ′′′′( x i ) + L
2! 3! 4!
⎨ 2 3 4
⎪ f ( x ) = f ( x ) − hf ′( x ) + h f ′′( x ) − h f ′′′( x ) + h f ′′′′( x ) + L
⎪⎩ i −1 i i
2!
i
3!
i
4!
i

⎡ h2 h4 ⎤
⇒ f ( x i +1 ) + f ( x i −1 ) = 2 ⎢ f ( x i ) + ′′
f ( xi ) + f ′′′′( x i ) + L⎥
⎣ 2! 4! ⎦

f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 ) h2
f ′′( x i ) = 2
− f ′′′′(ξ )
h 4!

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Central Finite Difference Expressions for 1D Domains


1 2 k-1 k k+1
x

h h h h h h
For state variable “u”, central FD expressions at discrete point “k” are:
du 1 (
1. = − 0.5 u k -1 + 0.5 u k +1 ) h = constant spacing between
dx h discrete points inside domain
d2u
2. = 1 ( u k -1 − 2 u k + u k +1 )
dx 2 h 2
d3u
3. = 1 ( − 0.5 u k -2 + u k -1 − u k +1 + 0.5 u k + 2 )
dx 3 h 3
d4u
4. = 1 ( u k -2 − 4 u k -1 + 6 u k − 4 u k +1 + u k + 2 )
dx 4 h 4
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
2. Numerical Differentiation & Differential Equations

Central Finite Difference Expressions for 1D Domains


1 2 k-1 k k+1
x

h h h h h h
FD Computation
Molecules

Derivative operator D = d / dx
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Forward Finite Difference Expressions for 1D Domains


1 2 k-1 k k+1
x

h h h h h h
For state variable “u”, forward FD expressions at discrete point “k” are:
du 1 (
1. = − u k + u k +1 ) h = constant spacing between
dx h discrete points inside domain
d2u
2. = 1 ( u k − 2 u k +1 + u k + 2 )
dx 2 h 2
d3u
3. = 1 ( − u k + 3 u k +1 − 3 u k + 2 + u k +3 )
dx 3 h 3
d4u
4. = 1 ( u k − 4 u k +1 + 6 u k + 2 − 4 u k +3 + u k + 4 )
dx 4 h 4
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
2. Numerical Differentiation & Differential Equations

Backward Finite Difference Expressions for 1D Domains


1 2 k-1 k k+1
x

h h h h h h
For state variable “u”, backward FD expressions at discrete point “k” are:
du 1 (
1. = u k − u k -1 ) h = constant spacing between
dx h discrete points inside domain
2
d u
2. = 1 ( u k − 2 u k -1 + u k -2 )
dx 2 h 2
d3u
3. = 1 ( u k − 3 u k -1 + 3 u k -2 − u k -3 )
dx 3 h 3
d4u
4. = 1 ( u k − 4 u k -1 + 6 u k -2 − 4 u k -3 + u k -4 )
dx 4 h 4
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

What is Main Shortcoming of Numerical Differentiation?


Numerical differentiation tends to amplify errors in the data. This error
amplification occurs because differentiation is subtractive. Thus, positive
and negative errors tend to add.

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


2. Numerical Differentiation & Differential Equations

Main Steps of Finite-Difference Methods


1. Divide continuous domain of problem into equally-spaced discrete points.
This is known as the finite difference grid.
2. At each discrete point in the FD grid, replace the governing differential
equations by the finite difference expressions to generate an algebraic
equation involving the unknown values of the state variables at the
current point and several neighbouring discrete points.
3. For discrete points near the boundaries, some phantom points may need
to be placed outside the domain of the problem.
4. Apply the boundary conditions. The values of state variables at phantom
points are determined in terms of values of the state variables at points
inside the domain.
5. Solve the resulting set of linear algebraic equations [A] {u} = {b} for the
unknown values of state variables “u” at the selected discrete points.

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Example: Simple Beam

Governing differential d 4 v w(x)


equation:
− =0
dx 4 EI
Boundary 1. v(x=0) = 0 ; essential
conditions:
2. v(x=L) = 0 ; essential
3. M(x=0) = 0 ; natural
d2v
− EI 2
=0
dx x= 0
4. M(x=L) = 0 ; natural
d2v
− EI 2
=0
dx x= L
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
v(x)

2. Numerical Differentiation & Differential Equations 0.07

0.06

Example: Simple Beam 0.05

0.04

E=1.0, I=100, L=4.0 0.03

w(x) = 2
0.02

0.01

wx
( x 3 − 2 Lx 2 + L3 )
0.00
v(x) = 0.0 1.0 2.0 3.0 4.0

24 E I x

= x ( x 3 − 8 x 2 + 64 ) M(x)

1200 4.5
4.0
3.5
3.0

wx 2.5

M(x) = (L− x) 2.0

2 1.5

= (4x − x 2 )
1.0
0.5
0.0
0.0 1.0 2.0 3.0 4.0
x

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Example: Simple Beam w=2


1. Divide beam using 5 grid points; h = 1 0 1 5 6
2. Replace diff eq by FD expression at
2 3 4
each grid point of unknown “v”:
@1: v1 = 0 (essential BC) L=4
@2: (v0 – 4v1 + 6v2 – 4v3 + v4) /14 = 0.02 d4v
= 0.02
(DEq + phantom 0) dx 4
@3: (v1 – 4v2 + 6v3 – 4v4 + v5) /14 = 0.02 (DEq) v ( x = 0; x = 4 ) = 0
2
@4: (v2 – 4v3 + 6v4 – 4v5 + v6) /14 = 0.02 ( d 2 v dx ) =0
(DEq + phantom 6) x= 0 ; x= L
@5: v5 = 0 (essential BC)
3. Apply remaining two natural BCs:
@1: (v0 – 2v1 + v2) /12 = 0 v0 = – v2
@5: (v4 – 2v5 + v6) /12 = 0 v6 = – v4

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


2. Numerical Differentiation & Differential Equations

Example: Simple Beam w=2


4. Formulate Equilibrium Equations 0 1 5 6
5v2 – 4v3 + v4 = 0.02
2 3 4
– 4v2 + 6v3 – 4v4 = 0.02
v2 – 4v3 + 5v4 = 0.02 L=4
⎡ 5 − 4 1 ⎤ ⎧ v2⎫ ⎧ 0.02 ⎫ d4v
⎢ − 4 6 − 4 ⎥ ⎪ v3⎪ = ⎪ 0.02 ⎪ = 0.02
dx 4
⎢ ⎥⎨ ⎬ ⎨ ⎬
⎢⎣ 1 − 4 5 ⎥⎦ ⎩ v4⎭ ⎩ 0.02 ⎪⎭
⎪ ⎪ ⎪ v ( x = 0; x = 4 ) = 0
2
( d 2 v dx ) =0
5. Solve [A] {x} = {b} for unknown {x}={v} x= 0 ; x= L
v2 = 0.05
v3 = 0.07
Exact FD Error (%)
v4 = 0.05 v2 0.048 0.050 5.26
The beam problem is symmetrical; thus,
the deflections are also symmetrical.
v3 0.067 0.070 5.00
Can discretization be simplified? v3 0.048 0.050 5.26
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Example: Simple Beam w=2


0 1 5 6
6. Calculate stress resultant
d2v d2v 2 3 4
M(x) = − EI(x) 2 = −100 2
dx dx L=4
@1: M2 = – 100 (v1 – 2v2 + v3) /12
= – 100 (0 – 2×0.05 + 0.07) / 12 = 3.0
@1: M3 = – 100 (v2 – 2v3 + v4) /12 = – 100 (0.05 – 2×0.07 + 0.05) / 12 = 4.0
@1: M4 = – 100 (v3 – 2v4 + v5) /12 = – 100 (0.07 – 2×0.05 + 0) / 12 = 3.0

Exact FD Error (%)


M2 3.00 3.00 0.00
M3 4.00 4.00 0.00
M4 3.00 3.00 0.00

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


2. Numerical Differentiation & Differential Equations

Example: Simple Beam -Symmetry w=2


1. Divide half of beam using 3 grid 0 1
points; h = 1
2 3 4 5
2. Replace diff eq by FD expression at
each grid point of unknown “v”: L=4
@1: v1 = 0 (BC)
d4v
@2: (v0 – 4v1 + 6v2 – 4v3 + v4) /14
= 0.02 = 0.02
dx 4
(DEq + phantom 0 + phantom 4)
v ( x = 0; x = 4 ) = 0
@3: (v1 – 4v2 + 6v3 – 4v4 + v5) /14 = 0.02 2
(DEq + phantom 4 + phantom 5) ( d 2 v dx ) =0
x= 0 ; x= L
3. Apply Conditions of Symmetry:
v4 = v2 v5 = v1 = 0
4. Apply remaining BC:
@1: (v0 – 2v1 + v2) /12 = 0
v0 = – v2
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

2. Numerical Differentiation & Differential Equations

Example: Simple Beam -Symmetry w=2


5. Formulate Equilibrium Equations 0 1
6v2 – 4v3 = 0.02 2 3 4 5
– 8v2 + 6v3 = 0.02
L=4
⎡ 6 − 4 ⎤ ⎧ v2⎫ ⎧ 0.02 ⎫
⎢ − 8 6 ⎥ ⎨ v3⎬ = ⎨ 0.02 ⎬ d4v
⎣ ⎦⎩ ⎭ ⎩ ⎭ = 0.02
dx 4
v ( x = 0; x = 4 ) = 0
6. Solve [A] {x} = {b} for unknown {x}={v} 2
( d 2 v dx ) =0
v2 = 0.05 x= 0 ; x= L
v3 = 0.07

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


Numerical Methods A-5

Lecture Agenda

1. Numerical Integration: Multiple Integrals

2. Numerical Differentiation & Differential Equations

3. Standard Eigenvalue Problem

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

Example: Buckling of Column


4 2 P P
Governing differential d v P d v
+ × 2 =0
equation: dx 4 E I dx x
L
Boundary 1. v(x=0) = 0 ; essential v
conditions: E=1.0, I=100, L=4.0
2. v(x=L) = 0 ; essential
3. M(x=0) = 0 ; natural P P
λ= =
d2v E I 100
− EI 2
=0 4
d v d2v
dx x= 0 +λ 2 =0
dx 4 dx
4. M(x=L) = 0 ; natural
d2v
− EI 2
=0
dx x= L
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
3. Standard Eigenvalue Problem

Example: Buckling of Column


1. Divide column using 5 grid points 0P 1 5 P 6
h=1 x
2 3 4
2. Replace diff eq by FD expression at
each grid point of unknown “v”: v L =L 4
@1: v1 = 0 (essential BC) d4v d2v
+ λ =0
@2: (v0 – 4v1 + 6v2 – 4v3 + v4) /14 dx 4 dx 2
+ λ [(v1 – 2v2 + v3) /12 ] = 0 v ( x = 0; x = 4 ) = 0
2
@3: (v1 – 4v2 + 6v3 – 4v4 + v5) /14 ( d 2 v dx ) =0
+ λ [(v2 – 2v3 + v4) /12 ] = 0 x= 0 ; x= L

@4: (v2 – 4v3 + 6v4 – 4v5 + v6) /14


+ λ [(v3 – 2v4 + v5) /12 ] = 0
@5: v5 = 0 (essential BC)
3. Apply remaining two natural BCs:
@1: (v0 – 2v1 + v2) /12 = 0 v0 = – v2
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

Example: Buckling of Column


3. Apply remaining two natural BCs: 0P 1 5 P 6
@5: (v4 – 2v5 + v6) /12 = 0 2 3 4 x
v6 = – v4
v L =L 4
4. Formulate Buckling Equations
d4v d2v
(5v2 – 4v3 + v4) + λ (– 2v2 + v3) = 0 + λ =0
dx 4 dx 2
(– 4v2 + 6v3 – 4v4) + λ (v2 – 2v3 + v4) = 0 v ( x = 0; x = 4 ) = 0
(v2 – 4v3 + 5v4) + λ (v3 – 2v4) = 0 2
( d 2 v dx ) =0
x= 0 ; x= L
⎡ 5 − 4 1 ⎤ ⎧ v2⎫ ⎡− 2 1 0 ⎤ ⎧ v2⎫ ⎧0 ⎫
⎪ ⎪
⎢ − 4 6 − 4 ⎥ ⎨ v3⎬ + λ ⎢ 1 ⎪ ⎪ ⎪ ⎪
− 2 1 ⎥ ⎨ v3⎬ = ⎨0 ⎬
⎢ 1 − 4 5 ⎥ ⎪ v4⎪ ⎢0 1 − 2 ⎥⎦ ⎪⎩ v4⎪⎭ ⎪⎩0 ⎪⎭
⎣ ⎦⎩ ⎭ ⎣
⎡ 5 − 4 1 ⎤ ⎧ v2⎫ ⎡2 −1 0 ⎤ ⎧ v2⎫ ⎧0 ⎫
⎪ ⎪
⎢ − 4 6 − 4 ⎥ ⎨ v3⎬ − λ ⎢ −1 ⎪ ⎪ ⎪ ⎪
2 −1⎥ ⎨ v3⎬ = ⎨0 ⎬
⎢ 1 − 4 5 ⎥ ⎪ v4⎪ ⎢0 −1 2 ⎥⎦ ⎪⎩ v4⎪⎭ ⎪⎩0 ⎪⎭
⎣ ⎦⎩ ⎭ ⎣
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
3. Standard Eigenvalue Problem

Example: Buckling of Column


0P 1 5 P 6
⎡ 5 − 4 1 ⎤ ⎧ v2⎫ ⎡ 2 −1 0 ⎤ ⎧ v2⎫ ⎧0 ⎫
⎢ − 4 6 − 4 ⎥ ⎨ v3⎬ − λ ⎢ −1 2 −1⎥ ⎪⎨ v3⎪⎬ = ⎪⎨0 ⎪⎬
⎪ ⎪ 2 3 4 x
⎢ 1 − 4 5 ⎥ ⎪ v4⎪ ⎢ 0 −1 2 ⎥ ⎪ v4⎪ ⎪0 ⎪ L =L 4
⎣ ⎦⎩ ⎭ ⎣ ⎦⎩ ⎭ ⎩ ⎭ v 4
[C] {x} [D] {x} {0} d v d2v
+ λ =0
dx 4 dx 2
Multiply both sides by [D]-1 P P
λ= =
⎡ 2 −1 0 ⎤ ⎧ v2⎫ ⎧ v2⎫ ⎧0 ⎫ E I 100
⎢ −1 2 −1⎥ ⎨ v3⎬ − λ ⎪⎨ v3⎪⎬ = ⎪⎨0 ⎪⎬
⎪ ⎪
v ( x = 0; x = 4 ) = 0
⎢ 0 −1 2 ⎥ ⎪ v4⎪ ⎪⎩ v4⎪⎭ ⎪⎩0 ⎪⎭
⎣ ⎦⎩ ⎭ ( d 2 v dx )
2
=0
[A] {x} – λ {x} = {0} x= 0 ; x= L

3 homogenous algebraic equations Exact Solution


Unknowns = 4 (v2, v3, v4, λ) !! π2EI π2EI
Buckling problem is indeterminate P= = = 0.617 E I
L2 42
Numerical Solution: λ = 0.586 λ = P E I = 0.617
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

What is the Difference between 2 Problems?


Problem 1 Problem 2
P P
x
L
v

Governing differential equation: Governing differential equation:


d 4 v w(x) d4v P d2v
− =0 + × =0
dx 4 EI dx 4 E I dx 2
Boundary Conditions: Boundary Conditions:
1. v(x=0) = 0 ; essential 1. v(x=0) = 0 ; essential
2. v(x=L) = 0 ; essential 2. v(x=L) = 0 ; essential
3. M(x=0) = 0 ; natural 3. M(x=0) = 0 ; natural
4. M(x=L) = 0 ; natural 4. M(x=L) = 0 ; natural
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
3. Standard Eigenvalue Problem

What is the Difference between 2 Problems?


Problem 1 Problem 2
P P
x

d 4 v w(x) d v P d2v
4
− =0 v
L + × =0
dx 4 EI dx 4 E I dx 2
4
d v w(x)
= d4v d2v λ=
P
dx 4 EI +λ 2 =0
dx 4 dx EI
Unknown Forcing
Response Term Unknown No
Response Forcing
Discretization Term
Discretization
[ A]{x} = {b}
Non-homogenous
[ A ]{ x } − λ { x } = { 0}
Algebraic Equations
Unique solution exist
[ B ]{ x } = { 0} [ B ] = [ A ] − λ [ I ]
If [A] is not singular Homogenous Algebraic Equations
det[A] ≠ 0 NO unique solution exist

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

What is the Difference between 2 Problems?


Problem 1 Problem 2
P P
x

d 4 v w(x) d v P d2v
4
− =0 v
L + × =0
dx 4 EI dx 4 E I dx 2
[ A]{x} = {b} [ A ]{ x } − λ { x } = { 0}
Equilibrium Problem [ B ]{ x } = { 0} [ B ] = [ A ] − λ[ I ]
Eigenvalue Problem
λ = eigenvalue or characteristic value
{x} = eigenvector

For each λ, we can determine {x}


as ratios or relative values that satisfy
eigenvalue problem

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

Philosophy of Standard Eigenvalue Problem


[ A ]{ x } − λ { x } = { 0}
[ A ]{ x } = λ { x }
Eigenvalue problem is a linear transformation using property matrix [A]
between solution vector {x} and its scaled image λ{x}, in same space
[ A ]{ x } − λ { x } = { 0}
[ A ]{ x } − λ [ I ]{ x } = { 0} {I } = Identity matrix
[ [ A ] − λ [ I ] ]{ x } = { 0}
[ B ]{ x } = { 0} [ B ] = [ A] − λ [ I ]
{x}= {0} Trivial solution of no response
{ x } = [ B ] −1 { 0} which occurs if [B]-1 exist
{x}≠ {0} Response exist, which occurs if [B]-1 does
NOT exist because [B] is singular matrix
whose determinant det[B] = 0
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

Applications of Standard Eigenvalue Problem


1. Buckling of Columns
2. Vibration of Structures
3. Principal Stresses
Solution Methods
1. Characteristic polynomial method
2. Vector iteration methods
3. Similarity transformation methods
4. Hybrid methods

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

Properties of Eigenvalues and Eigenvectors if [A] is Real,


Symmetric and Positive Definite Matrix of Size N×N
1. There are “N” eigenvalues and “N” eigenvectors
2. All “N” eigenvalues are real and positive (λk > 0)
λmax ≥ max A(k,k)
λmin ≤ min A(k,k)
3. det(A) = λ1 × λ2 × λ3 × … × λN
4. Different eigenvectors are orthogonal to each other
{x}kT.{x}j = 0 (k ≠ j)
5. Different eigenvectors are orthogonal to each other with respect to [A]
{x}kT [A] {x}j = 0 (k ≠ j)

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

Bounds for Eigenvalues Using Gerschgorin Theorems


Theorem 1
Every eigenvalue lies in at least one disc with center A(k,k) and radius Rk
Rk = sum of absolute values of off-diagonal entries in row k
N
Rk = ∑ ak j
j =1
j≠k

Theorem 2
There is one eigenvalue inside each isolated disc. If “m” number of discs
intersect, then there are “m” eigenvalues inside intersecting discs.

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

Bounds for Eigenvalues Using Gerschgorin Theorems


Example
k A(k,k) Rk


4 1 − 2 ⎤⎥
[A] = ⎢⎢ 1 14 1 ⎥⎥ 1 4 1+2=3

⎢⎣ −2 0 8 ⎥⎥⎦ 2 14 1+1=2
1 ≤ λ1 ≤ 10 3 8 2+0=2
1 ≤ λ2 ≤ 10 k=1
k=3 k=2
12 ≤ λ3 ≤ 16
3 2 2
But min A(k,k) = 4 12 16
max A(k,k) = 14 1 10
4 8 14
1 ≤ λ1 = λmin ≤ 4
λ1 < λ2 ≤ 10 One Eigenvalue
Two Eigenvalues Inside isolated disc
14 ≤ λ3 = λmax ≤ 16 Inside 2 intersecting discs
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


1. Characteristic Polynomial
[ A ]{ x } = λ { x }
[ [ A ] − λ [ I ] ]{ x } = { 0}
[ B ]{ x } = { 0}
[B] must be singular for response to exist: det[B] = 0

det [ [ A ] − λ [ I ] ] = 0
Expansion of det[B] gives a polynomial of order “N” in λ, which is known
as the characteristic equation or characteristic polynomial

c N λ N + c N −1 λ N −1 + K + + c 2 λ 2 + c1 λ + c 0 = 0

The roots of characteristic equation are eigenvalues λr , r=1,2,…,N

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


1. Characteristic Polynomial
⎡ 32 − 16 ⎤
Example 1 [ A ] = ⎢ ⎥
⎣ − 16 16 ⎦
⎡ 32 − λ − 16 ⎤
[ B ] = [ [ A] − λ [ I ] ] = ⎢ ⎥
⎣ − 16 16 − λ ⎦
det [ [ A ] − λ [ I ] ] = 0
( 32 − λ ) × (16 − λ ) − ( −16 ) × ( −16 ) = 0
λ 2 − 48 λ + 256 = 0 λ 1 = 41 .89
λ 2 = 6.11

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


1. Characteristic Polynomial
⎡6 4 3⎤
Example 2 [ A ] = ⎢ 4 10 6 ⎥
⎢3 6 8⎥
⎣ ⎦
⎡6 − λ 4 3 ⎤
[ B ] = [ [ A] − λ [ I ] ] = ⎢ 4 10 − λ 6 ⎥
⎢ 3 6 8 − λ ⎥⎦

det [ [ A ] − λ [ I ] ] = 0
10 − λ 6 4 6 4 10 − λ
(6 − λ) × − 4× + 3× =0
6 8−λ 3 8−λ 3 6
λ3 − 14 λ 2 − 2 λ + 15 = 0 λ 1 = 17 .29
λ 2 = 3.87
λ 3 = 2.84
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
3. Standard Eigenvalue Problem

How to Calculate Characteristic Polynomial and Eigenvalues


By MATLAB?
1. poly(A)
Returns the coefficients of characteristic polynomial of matrix [A] arranged
in a descending order

1. Use “poly” function to generate characteristic polynomial of [A]


2. Use “roots” function to determine roots of characteristic polynomial,
which are eigenvalues of [A]

⎡ 32 − 16 ⎤
>> A = [32,-16; -16,16];
Example 1 [ A ] = ⎢ ⎥
>> cheq = poly(A)
⎣ − 16 16 ⎦ cheq =
1 -48 256
>> lamda = roots(cheq)
lamda =
41.8885
6.1115

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Characteristic Polynomial and Eigenvalues


By MATLAB?
⎡6 4 3⎤
Example 2 [ A ] = ⎢ 4 10 6 ⎥
⎢3 6 8⎥
⎣ ⎦
>> A = [6,4,3; 4,10,6; 3,6,8];
>> cheq = poly(A)
cheq =
1.0000 -24.0000 127.0000 -190.0000
>> lamda = roots(cheq)
lamda =
17.2904
3.8704
2.8392

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


2. Iterative Similarity Transformations ⎡ a11 0 K 0 ⎤
⎢ 0 a 22 K 0 ⎥
[ A ]{ x } = λ { x } [ A ] = ⎢ ⎥
⎢ M M O M ⎥
If [A] is a diagonal matrix (or triangular matrix) ⎢⎣ 0 0 0 a NN ⎥⎦
⎡ a11 − λ 0 K 0 ⎤
⎢ a 22 − λ K 0 ⎥
[ [ A] − λ [ I ] ] = ⎢ 0 ⎥
⎢ M M O M ⎥
⎢⎣ 0 0 0 a NN − λ ⎥⎦
det [ [ A ] − λ [ I ] ] = 0
( a11 − λ ) × ( a 22 − λ ) × K × ( a NN − λ ) = 0
( a11 − λ ) = 0 λ 1 = a11
Diagonal entries
( a 22 − λ ) = 0 λ 2 = a 22 are eigenvalues
( a NN − λ ) = 0 λ N = a NN
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


2. Iterative Similarity Transformations
Philosophy is to transform matrix [A] into a similar matrix [As] which is
triangular or diagonal using transformation matrix [H]
[ As ] = [ H ] −1 [ A ] [ H ]
The above similarity transformation is repeated successively until [A] is
reduced to an acceptable triangular or diagonal matrix [As], whose
eigenvalues λs = its diagonal entries
[ As1 ] = [ H ] −1 [ A ] [ H ]
[ As 2 ] = [ H ] −1 [ As1 ] [ H ]
[ As 3 ] = [ H ] −1 [ As 2 ] [ H ]
[ As k ] = [ H ] −1 [ As k −1 ] [ H ]
Hence, eigenvalues λ of [A] = eigenvalues λs of [As]
Good for small-size and dense matrices to calculate eigenvalues
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


2. Iterative Similarity Transformations
Proof eigenvalues λ of [A] = eigenvalues λs of [As]
Eigenvalue problem of similar matrix [ As ]{ xs } = λs { xs }
[ H ] −1 [ A ] [ H ]{ xs } = λs { xs }
Premultiply by [H]
[ H ] [ H ] −1 [ A ] [ H ]{ xs } = λs [ H ] { xs }
[ A ] [ H ]{ xs } = λs [ H ] { xs }
[ A ] { xs H } = λs { xs H }
Compare with eigenvalue problem of [A]
[ A ]{ x } = λ { x }
λ = λs and { x } = [ H ] { xs }
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


2. Iterative Similarity Transformations Using L and U of [A]
(LU Iterations)
Factorize [ A ] = [ L ] [U ]
Select [ H ] = [ L ]
[ As ] = [ L ] −1 [ A ] [ L ] = [ L ] −1 [ L ] [U ] [ L ]
[ As ] = [U ] [ L ]
If [A] is symmetric and positive definite, then similar matrix [As] by LU
iterations will be diagonal matrix, whose diagonal elements are λ of [A]
arranged in a descending order
[ A ] → [ L ] [U ] [ As1 ] → [ L1 ] [U 1 ] [ As 2 ] → [ L 2 ] [U 2 ]
[ As1 ] = [U ] [ L ] [ As 2 ] = [U 1 ] [ L1 ] [ As 3 ] = [U 2 ] [ L 2 ]

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


2. Iterative Similarity Transformations Using L and U of [A]
(LU Iterations)
Convergence Criteria
1. { λ } new − { λ } old ∞
≤ ε tol for k = 1, 2, 3, …, n
εtol = pre-specified tolerance for error magnitude in numerical
values of λ-vector. So, round-off errors can be controlled
2. Maximum Number of Iterations k > k max

3. Norm of residual vector [ A[{ x } − λ { x } ≤ ε tol

4. Norm of sum of absolute values of off-diagonal entries of [L] ≤ εtol

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

Algorithm for LU Iterations


Input: matrix [A], maximum iterations
Output: vector of eigenvalues {EG}, number of iterations “nit”
start
1. nr = number of rows of [A]
2. nc = number of columns of [A]
3. if ( nc ≠ nr ) then print error message and end
4. initialize [EG] to zeros
5. initialize [As] = [A]
6. nit = 0
6. Repeat for each kth sweep (1 to kmax)
nit = nit + 1
tmp = EG
Factorize [As_old] into [Lk] and [Uk]
[As_new] = [Uk]*[Lk]
[EG] = diagonal elements of [As_new]
if norm(EG - tmp) <= etol, then end iterations
end
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
MATLAB Module for LU Iterations

function [EG] = LUiter(A,kmax,etol)


% LU iterations to determine eigenvalues of matrix [A]
[nr, nc] = size(A);
if (nc ~= nr), error(‘A NOT Square’); end
EG = zeros(nr,1);
As = A;
nit = 0;
for k = 1:kmax
nit = nit + 1;
tmp = EG;
[Lk,Uk] = lu(As);
As = Uk * Lk;
EG = diag(As);
if norm(EG – tmp) <= etol, break, end
end
end

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


2. Iterative Similarity Transformations Using L and U of [A]
(LU Iterations)
⎡ 32 − 16 ⎤
>> A = [32,-16; -16,16];
Example 1 [ A ] = ⎢ ⎥
>> [val,nit]=LUiter(A,10,0.01)
⎣ − 16 16 ⎦ val =
41.8876
6.1124
nit =
5
>> A = [32,-16; -16,16];
>> [val,nit]=LUiter(A,10,10^(-10)
val =
41.8885
6.1115 >> A = [32,-16; -16,16];
nit = >> [val,nit]=LUiter(A,100,10^(-10)
10 val =
41.8885
6.1115
nit =
15

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


2. Iterative Similarity Transformations Using L and U of [A]
(LU Iterations) >> A =[6,4,3; 4,10,6; 3,6,8];
⎡6 4 3⎤ >> [val,nit]=LUiter(A,10,0.001)

Example 2 [ A ] = 4 10 6 ⎥ val =
⎢3 6 8⎥ 17.2904
⎣ ⎦ 3.8486
2.8610
nit =
>> A =[6,4,3; 4,10,6; 3,6,8]; 10
>> [val,nit]=LUiter(A,50,0.001)
val =
17.2904
3.8678 >> A = [32,-16; -16,16];
2.8417 >> [val,nit]=LUiter(A,100,10^(-10)
nit = val =
17 17.2904
3.8704
2.8392
nit =
69

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Eigenvalues?


2. Iterative Similarity Transformations
Error Analysis
[ As + εAs ] = [H]-1 [ A + εAs ] [H]
[ εAs ] = [H]-1 [ εAs ] [H]
|| εAs || = || [H]-1 [ εAs ] [H] ||
Apply Cauchy-Schwarz inequality of norms
|| εAs || ≤ || [H]-1 || × || εAs || × || H] ||

|| εAs || ≤ || [H] || × || H] -1 || × || εAs ||


|| εAs || ≤ Cond [H] × || εAs ||

If Cond [H] ≈ 1 or is small, then no error amplification

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate ALL Eigenvalues By MATLAB?


2. eig
“eig” function returns a column vector of ALL eigenvalues of matrix [A]
arranged in an ascending order
Syntax eig(A)
>> A = [32,-16; -16,16];
⎡ 32 − 16 ⎤ >> Val = eig(A)
Example 1 [ A ] = ⎢ ⎥ Val =
⎣ − 16 16 ⎦ 6.1115
41.8885

>> A =[6,4,3; 4,10,6; 3,6,8];


⎡6 4 3⎤ >> Val = eig(A)
Example 2 [ A ] = ⎢ 4 10 6 ⎥
Val =
⎢3 6 8⎥ 2.8392
⎣ ⎦ 3.8704
17.2904

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Largest Eigenvalue?


Power Iterations
Iterative method to determine largest eigenvalue λN = λmax of matrix [A].
In this method, the corresponding eigenvector {x}N is also calculated.
[ A ]{ x } = λ { x }
Initial guess = {xo} ( {xo} = {1, 1, 1, …, 1}T )
New image = [ b1 ] = [ A ]{ x 0 }
λ 1 = b1 E
{ x1 } = (1 λ 1 ) × {b1 }
For kth iteration { b k } = [ A ]{ x k −1 } Repeat till convergence
λ k = bk λ k − λ k −1
E
≤ ε tol
{ x k } = (1 λ k ) × {b k } λk

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate Largest Eigenvalue?


Power Iterations
⎡ 32 − 16 ⎤
Example 1 [ A] = ⎢ ⎥
⎣ − 16 16 ⎦
>> A = [32,-16; -16,16];
>> [egmax,egvec,nit] = powerit(A,10,0.0001)
egmax =
41.8885
egvec = >> A = [32,-16; -16,16];
0.8508 >>[egmax,egvec,nit]=powerit(A,10,10^-15)
-0.5255 egmax =
nit = 41.8885
5 egvec = >> A = [32,-16; -16,16];
0.8507 >>[egmax,egvec,nit]=powerit(A,100,10^-15)
-0.5257 egmax =
nit = 41.8885
10 egvec =
0.8507
-0.5257
nit =
12

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Largest Eigenvalue?


Power Iterations ⎡6 4 3⎤
Example 2 [ A ] = ⎢ 4 10 6 ⎥
⎢3 6 8⎥
⎣ ⎦
>> A =[6,4,3; 4,10,6; 3,6,8];
>> [egmax,egvec,nit] = powerit(A,10,0.0001)
egmax =
17.2904 >> A =[6,4,3; 4,10,6; 3,6,8];
egvec = >>[egmax,egvec,nit]=powerit(A,10,10^-15)
0.4049 egmax =
0.7031 17.2904 >> A =[6,4,3; 4,10,6; 3,6,8];
0.5846 egvec = >>[egmax,egvec,nit]=powerit(A,100,10^-15)
nit = 0.4045 egmax =
4 0.7032 17.2904
0.5847 egvec =
nit = 0.4045
10 0.7032
0.5847
nit =
13
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
3. Standard Eigenvalue Problem

How to Calculate Largest Eigenvalue?


Power Iterations
Convergence rate depends on:
1. Ratio λN / λN-1 (largest eigenvalue / next largest eigenvalue)
As this ratio increases, the rate of convergence improves as adjacent
eigenvalues are well separated
2. Initial guess should be in direction of {x}

Power iterations are effective if [A] is large and sparse, and when λN and
λN-1 are well separated

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Smallest Eigenvalue?


1. Power Iterations on Shifted Matrix
1. Select a shift S > λmax (apply Gerschgorin Theorems)
2. Shift matrix [A], so that shifted matrix [As] = [A] – S [I]
3. Apply Power iterations to calculate largest eigenvalue of shifted
matrix [As] and its eigenvector, λS-max and {x}S
4. Smallest eigenvalue of matrix [A] and its eigenvector are given by
λ1 = λmin = S – λS-max
{x} = {x}1 >> A = [32,-16; -16,16];
>>[egval,egvec,nit]=powershift(A,100,50,10^-15)
egval =
Example 1 6.1115
egvec =
⎡ 32 − 16⎤
[ A] = ⎢ ⎥
0.5257
⎣ − 16 16 ⎦
0.8507
nit =
12

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate Smallest Eigenvalue?


1. Power Iterations on Shifted Matrix
⎡6 4 3⎤
Example 2 [ A ] = ⎢ 4 10 6 ⎥
⎢3 6 8⎥
⎣ ⎦

>> A =[6,4,3; 4,10,6; 3,6,8];


>>[egval,egvec,nit] = powershift(A,200,20,10^-10)
egval =
2.8392
egvec =
-0.2533
0.7005
-0.6672
nit =
153

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Smallest Eigenvalue?


2. Inverse Iterations
[ A ]{ x } = λ { x }
{ x } = λ [ A ] −1 { x }
1
[ A ] −1 { x } = { x }
λ
Eigenvalues of inverse matrix [A]-1 = 1/eigenvalues of [A]

λmax of [A]-1 = 1/λmin of [A]

λmax of [A]-1 can be determined by Power iterations on [A]-1


However, instead of constructing [A]-1, we solve a system of algebraic
linear equations

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate Smallest Eigenvalue?


2. Inverse Iterations
[ A ]{ x } = λ { x }
1
[ A ]{ x } × = { x }
λ
Initial guess = {xo} ( {xo} = {1, 1, 1, …, 1}T )
Solve for new image [ A ]{b1 } = { x 0 }
λ 1 = b1 E
{ x1 } = (1 λ 1 ) × {b1 }
Repeat till
For kth iteration: solve for {bk} [ A ]{b k } = { x k −1 }
convergence
λ k = bk E λ k − λ k −1
≤ ε tol
{ x k } = (1 λ k ) × {b k } λk
λ min = 1 λ 1
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate Smallest Eigenvalue?


2. Inverse Iterations
Example 1 >> A = [32,-16; -16,16];
>> [egmin,egvec,nit] = invit(A,50,10^-15)
⎡ 32 − 16⎤ egmin =
[ A] = ⎢ ⎥ 6.1115
⎣ − 16 16 ⎦ egvec =
0.5257
0.8507
nit =
11
>> A =[6,4,3; 4,10,6; 3,6,8];
>> [egmin,egvec,nit] = invit(A,100,10^-15)
Example 2 egmin =
⎡6 4 3⎤ 2.8392
egvec =
[ A ] = ⎢ 4 10 6 ⎥ 0.2532
⎢3 6 8⎥ -0.7005
⎣ ⎦ 0.6672
nit =
56
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
3. Standard Eigenvalue Problem

How to Calculate Eigenvectors?


Direct Method
Eigenvectors are calculated by back substitution of each eigenvalue λr in
the standard eigenvalue problem
[ A ]{ x } r = λ r { x } r
[ [ A ] − λ r [ I ] ]{ x } r = { 0}
[ B ] r { x } r = { 0}
This is a set of homogeneous linear equations, so there is no unique
eigenvector. But for each λr , we can determine {x}r as ratios or
relative values by assuming one of the entries of {x}r

This means that eigenvector {x}r is determined within a multiplicative


factor
Scale {x}r so that eigenvector has a unit magnitude { x } r =
1
× { x} r
{ x} r
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem


>> A = [32,-16; -16,16];
How to Calculate Eigenvectors? >> cheq = poly(A);
>> lamda = roots(cheq)
Direct Method
⎡ 32 − 16⎤
lamda =
Example 1 [ A] = ⎢ ⎥
41.8885
⎣ − 16 16 ⎦ 6.1115
For λ1 = 41.8885
⎡32 − 41.8885 − 16 ⎤ ⎧ x1 ⎫ ⎧0⎫
[ [ A ] − λ 1 [ I ] ]{ x }1 = { 0} ⎢ − 16 16 − 41.8885⎥ ⎨ x ⎬ = ⎨⎩0⎬⎭
⎣ ⎦ ⎩ 2 ⎭1
⎡ − 9.8885 − 16 ⎤ ⎧ x1 ⎫ ⎧0⎫
⎢ − 16 − 25.8885⎥ ⎨ x ⎬ = ⎨⎩0⎬⎭
⎣ ⎦ ⎩ 2 ⎭1
− 9.8885 x1 − 16 x 2 = 0 By eq. (1): x1 = − 1.618 x2
SAME !!
− 16 x1 − 25 .8885 x 2 = 0 By eq. (2): x1 = − 1.618 x2
x2 = 1.0 By eq. (1): x1 = − 1.618 {x}1 = {− 1.618, 1.0}T
⎧ − 0.8506⎫
|| {x}1 || = 1.9021 { x}1 = ⎨ ⎬
⎩ 0.5257⎭
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I
3. Standard Eigenvalue Problem
>> A = [32,-16; -16,16];
How to Calculate Eigenvectors? >> cheq = poly(A);
>> lamda = roots(cheq)
Direct Method
⎡ 32 − 16⎤
lamda =
Example 1 [ A] = ⎢ ⎥
41.8885
⎣ − 16 16 ⎦ 6.1115
For λ2 = 6.1115
⎡32 − 6.1115 − 16 ⎤ ⎧ x1 ⎫ ⎧0⎫
[ [ A ] − λ 1 [ I ] ]{ x }1 = { 0} ⎢ − 16 16 − 6.1115⎥ ⎨ x ⎬ = ⎨⎩0⎬⎭
⎣ ⎦ ⎩ 2 ⎭2
⎡ 25.8885 − 16 ⎤ ⎧ x1 ⎫ ⎧0⎫
⎢ − 16 9.8885⎥ ⎨ x ⎬ = ⎨⎩0⎬⎭
⎣ ⎦ ⎩ 2 ⎭2
25 .8885 x1 − 16 x 2 = 0 By eq. (1): x1 = 0.618 x2
SAME !!
− 16 x1 + 9.8885 x 2 = 0 By eq. (2): x1 = 0.618 x2
x2 = 1.0 By eq. (1): x1 = 0.618 {x}2 = {0.618, 1.0}T
⎧ 0.5257⎫
|| {x}2 || = 1.1756 { x} 2 = ⎨ ⎬
⎩ 0.8506⎭
Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem


>> A = [6,4,3; 4,10,6; 3,6,8];
>> cheq = poly(A);
How to Calculate Eigenvectors? >> lamda = roots(cheq)
Direct Method ⎡ 6 4 3 ⎤ lamda =
17.2904
Example 2 [ A ] = ⎢ 4 10 6 ⎥ 3.8704
⎢3 6 8⎥ 2.8392
⎣ ⎦
For λ1 = 17.2904
[ [ A ] − λ 1 [ I ] ]{ x }1 = { 0}
⎡ 6 −17.2904 4 3 ⎤ ⎧ x1 ⎫ ⎧0⎫
⎢ 4 10 −17.2904 6 ⎥ ⎪⎨ x2 ⎪⎬ = ⎪⎨0⎪⎬
⎢ 3 6 8 −17.2904⎥⎦ ⎪⎩ x3 ⎪⎭ ⎪⎩0⎪⎭
⎣ 1

⎡ −11.2904 4 3 ⎤ ⎧ x1 ⎫ ⎧0⎫
⎢ ⎪ ⎪ ⎪ ⎪
4 − 7.2904 6 ⎥ ⎨ x 2 ⎬ = ⎨0 ⎬
⎢ 3 6 − 9.2904⎥⎦ ⎪⎩ x3 ⎪⎭ ⎪⎩0⎪⎭
⎣ 1

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem
>> A = [6,4,3; 4,10,6; 3,6,8];
>> cheq = poly(A);
How to Calculate Eigenvectors? >> lamda = roots(cheq)
Direct Method ⎡ 6 4 3 ⎤ lamda =
17.2904
Example 2 [ A ] = ⎢ 4 10 6 ⎥ 3.8704
⎢3 6 8⎥ 2.8392
⎣ ⎦
Assume x3 = 1.0
⎧ x1 ⎫
⎡ − 11.2904 4 3 ⎤ ⎪ ⎪ ⎧0 ⎫
=
− 7.2904 6⎥⎦ ⎨ 2 ⎬ ⎨⎩0⎬⎭
⎢⎣ x
4
⎪⎩1.0⎪⎭
1

⎡ −11.2904 4 ⎤ ⎧ x1 ⎫ ⎧ − 3⎫ ⎧ x1 ⎫ ⎧ 0.6918⎫
= ⎨ x ⎬ = ⎨1.2025 ⎬
⎢⎣ 4 − 7.2904⎥⎦ ⎨⎩ x2 ⎬⎭1 ⎨⎩− 6 ⎬⎭ ⎩ 2 ⎭1 ⎩ ⎭
⎧ x1 ⎫ ⎧ 0.6918⎫ ⎧ x1 ⎫ ⎧ 0.4045 ⎫
⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪
⎨ x 2 ⎬ = ⎨1.2025 ⎬ || {x}1 || = 1.7101
⎨ x 2 ⎬ = ⎨ 0.7032 ⎬
⎪⎩ x 3 ⎪⎭ ⎪⎩ 1.0 ⎪⎭ ⎪⎩ x 3 ⎪⎭ ⎪⎩ 0.5848 ⎪⎭
1 1

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

How to Calculate ALL Eigenvalues and Eigenvectors By


MATLAB?
3. eig
“eig” function returns:
1. Full matrix whose columns are the eigenvectors of matrix [A]
2. Diagonal matrix whose diagonal entries are the eigenvalues of [A]

Syntax [egvec,egvals] = eig(A)

⎡ 32 − 16 ⎤ >> A = [32,-16; -16,16];


Example 1 [ A ] = ⎢ ⎥ >> [egvec,egvals] = eig(A)
⎣ − 16 16 ⎦ egvec =
-0.5257 -0.8507
-0.8507 0.5257
egvals =
6.1115 0
0 41.8885

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I


3. Standard Eigenvalue Problem

How to Calculate ALL Eigenvalues and Eigenvectors By


MATLAB?
3. eig
“eig” function returns:
1. Full matrix whose columns are the eigenvectors of matrix [A]
2. Diagonal matrix whose diagonal entries are the eigenvalues of [A]

Syntax [egvec,egvals] = eig(A)

⎡6 4 3⎤ >> A =[6,4,3; 4,10,6; 3,6,8];


Example 2 [ A ] = ⎢ 4 10 6 ⎥
>> [egvec,egvals] = eig(A)
⎢3 6 8⎥ egvec =
⎣ ⎦ -0.2532
0.7005
0.8788
-0.1218
0.4045
0.7032
-0.6672 -0.4614 0.5847
egvals =
2.8392 0 0
0 3.8704 0
0 0 17.2904

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

3. Standard Eigenvalue Problem

Bounds for Eigenvalues Using Gerschgorin Theorems

Prof. Nayer El-Esnawy – CEI-SC-I 300 Scientific Computing I

Potrebbero piacerti anche