ECE257 Numerical Methods andECE257 Numerical Methods andScientific ComputingScientific Computing
Ordinary Differential EquationsOrdinary Differential Equations
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
TodayToday’’s class:s class:
•• Boundary Value ProblemsBoundary Value Problems
•• Eigenvalue ProblemsEigenvalue Problems
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Boundary Value ProblemsBoundary Value Problems
•• Auxiliary conditionsAuxiliary conditions
–– nn-th order equation requires -th order equation requires nn conditions conditions
–– Initial value conditionsInitial value conditions•• All All nn conditions are specified at the same conditions are specified at the same
value of the independent variablevalue of the independent variable
–– Boundary value conditionsBoundary value conditions•• The The nn conditions are specified at different conditions are specified at different
values of the independent variablevalues of the independent variable
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Initial value conditionsInitial value conditions
From Numerical Methods for Engineers, Chapra and Canale, Copyright © The McGraw-Hill Companies, Inc.
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Boundary value conditionsBoundary value conditions
From Numerical Methods for Engineers, Chapra and Canale, Copyright © The McGraw-Hill Companies, Inc.
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Types of Boundary ConditionsTypes of Boundary Conditions
)( ayay =
)()(
α=⋅+⋅ aybdx
ady a
)(
α=== dx
ady
dx
dy
ax
• Simple B.C (Dirichlet B.C): The value of theunknown function is given at the boundary.
• Neumann B.C.: The derivative of the unknownfunction is given at the boundary.
• Mixing B.C.: The combination of the unknownfunction’s value and derivative is given at theboundary.
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Boundary Value ProblemsBoundary Value Problems
•• Shooting MethodShooting Method
–– Convert the boundary value problem into anConvert the boundary value problem into anequivalent initial value problem by choosingequivalent initial value problem by choosingvalues for all dependent variables at onevalues for all dependent variables at oneboundaryboundary
•• Relaxation MethodRelaxation Method
–– Choose values along the range of theChoose values along the range of theintegration and gradually adjust values sointegration and gradually adjust values sothat they satisfy the integral and boundarythat they satisfy the integral and boundaryvaluesvalues
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Shooting MethodShooting Method
•• Solve an Solve an NNth order ODE from th order ODE from xx11 toto x x22
•• Assume Assume nn11 boundary conditions at boundary conditions at xx11 and and nn22boundary conditions at boundary conditions at xx22
•• There are There are nn22=N-n=N-n11 freely specifiable starting values freely specifiable starting valuesat at xx11
•• Guess at those Guess at those nn22 values and then solve the values and then solve theresulting initial value ODE at resulting initial value ODE at xx22
•• Check if the boundary conditions are satisfied at Check if the boundary conditions are satisfied at xx22..If not, adjust the If not, adjust the nn22 values at values at xx11 and try again. and try again.
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Shooting Method ExampleShooting Method Example
•• Convert to first-orderConvert to first-order
€
d2ydx 2
+ 0.01 20 − y( ) = 0 y 0( ) = 40,y 10( ) = 200
€
dydx
= z y 0( ) = 40,y 10( ) = 200
dzdx
+ 0.01 20 − y( ) = 0
•• One free unspecified value at x=0 - guess aOne free unspecified value at x=0 - guess avalue for z(0)value for z(0) €
z 0( ) =10
•• Use RK method or any other method toUse RK method or any other method tosolve the ODE at x=10solve the ODE at x=10
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Shooting Method ExampleShooting Method Example
•• Using RK method with an initial guess of Using RK method with an initial guess of z(z(00)=)=1010 we get we gety(y(1010)=)=168.3797168.3797
•• The initial condition was The initial condition was y(y(1010)=)=200,200, so try again so try again
•• Using RK method with an initial guess of Using RK method with an initial guess of z(z(00)=2)=200 we get we gety(y(1010)=)=285.8980285.8980
•• With two guesses and a linear ODE, we can interpolateWith two guesses and a linear ODE, we can interpolateto find the correct valueto find the correct value
€
z 0( ) =10 +20 −10
285.8980 −168.3797200 −168.3797( )
=12.6907
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Shooting Method ExampleShooting Method Example
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Shooting MethodShooting Method
•• If the ODE is non-linear, then you have to recast theIf the ODE is non-linear, then you have to recast theproblem as solving a series of root problemsproblem as solving a series of root problems
•• Think of the guessed values as a Think of the guessed values as a nn22 size vector size vector VV
•• That vector That vector VV will generate a will generate a yy(x(x22)) vector after vector aftersolving the ODEsolving the ODE
•• The The yy(x(x22)) vector should equal the boundary value vector should equal the boundary valueconditions at conditions at xx22
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Shooting MethodShooting Method
€
discrepancy = BV2 x2,y( ) − y
•• Since Since y y is a function of is a function of VV, you can create a new, you can create a newdiscrepancy function discrepancy function FF that is dependent on that is dependent on VV
•• The problem then becomes to zero the discrepancyThe problem then becomes to zero the discrepancy
•• We donWe don’’t know t know F F so we cant use normal root-so we cant use normal root-solving methodssolving methods
•• But we can approach it in a Newton-RaphsonBut we can approach it in a Newton-Raphsonmanner by iteratively looking at the finite differencemanner by iteratively looking at the finite differencederivativesderivatives
€
discrepancy = F V( )
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Shooting MethodShooting Method
•• The problem then becomes to zero the discrepancy by solvingThe problem then becomes to zero the discrepancy by solvingthe following linear systemthe following linear system
€
α[ ] ⋅ δV = −F
α ij =∂Fi∂Vj
∂Fi∂Vj
≈Fi V1,K,V j + ΔV j ,K,Vn2( ) − Fi V1,K,V j ,K,Vn2( )
ΔV j
•• The vector The vector VV can be adjusted with the results of the solution can be adjusted with the results of the solution
€
Vnew = Vold + δV
•• However, you may need multiple cycles to solve for However, you may need multiple cycles to solve for VV
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Shooting MethodShooting MethodGuess initial values of vGuess initial values of vii (i=1 to n (i=1 to n22))for iter=1 to nitersfor iter=1 to nitersyy22 = Solve ODE at x = Solve ODE at x22F=BV-yF=BV-y22for j=1 to nfor j=1 to n22
vvjj= v= vjj++∆∆vvjjyy’’ = Solve ODE at x = Solve ODE at x22
FF’’=BV-y=BV-y’’for i=1 to nfor i=1 to n22
a[i][j] = (Fa[i][j] = (F’’[i]-F[i])/[i]-F[i])/∆∆vvjjendforendforrestore vrestore vjj
endforendforlinear solve (alinear solve (a••dv=-F)dv=-F)v = v + dvv = v + dvcheck errorcheck error
endforendfor
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Finite-Difference Method (FDM)Finite-Difference Method (FDM)
€
y' '= p(x)y '+q(x)y + r(x) y(a) =α and y(b) = β
Approximate the derivatives using numerical difference schemes.
)(2
')('
),(2
'')(''
. segments. equaln into range theDividing
211
22
11
hOh
yyyxy
hOh
yyyyxy
n
abxh
iiii
iiiii
+−
==
++−
==
−=Δ=
−+
−+
x0 =a x1 xn=b
h
xixi-1xi+1
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
FiniteFinite-Difference Method (FDM) (continued)-Difference Method (FDM) (continued)
• Substituting the derivatives by approximations and then we have a set of discretized equations
€
At i =1,2,.......n −1
yi+1 − 2yi + yi−1h2
= piyi+1 − yi−12h
+ qiyi + ri
Multiply both sides by h2.
(1+ pih2)yi-1 - (2 + qih
2)yi + (1− pih2)yi+1 = h2ri
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Finite-Difference Method (FDM) (continued)Finite-Difference Method (FDM) (continued)
€
For i =1.
-(2 + q1h2)y1 + (1− p1
h2)y2 = h2r1 − (1+ p1
h2)α
For i = 2,3,......,n − 2,
(1+ pih2)yi-1 - (2 + qih
2)yi + (1− pih2)yi+1 = h2ri
For i = n −1,
(1+ pih2)yn−2 - (2 + qih
2)yn−1 = h2rn−1 − (1− pn−1h2)β
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Matrix Form of Matrix Form of EquationEquation SystemSystem
€
If h = a-b7
and n = 7, noticing that y(a) =α and y(b) = β.
-(2 + q1h2) 1− p1
h2
0 0 0 0
1+ p2h2
-(2 + q2h2) 1− p2
h2
0 0 0
0 1+ p3h2
-(2 + q3h2) 1− p3
h2
0 0
0 0 1+ p4h2
-(2 + q4h2) 1− p4
h2
0
0 0 0 1+ p5h2
-(2 + q5h2) 1− p5
h2
0 0 0 0 1+ p6h2
-(2 + q6h2)
y1y2y3y4y5y6
=
h2r1 − (1+ p1h2)α
h2r2h2r3h2r4h2r5
h2r6 − (1− p6h2)β
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
FDM ExampleFDM Example
€
d2ydx 2
+ 0.01 20 − y( ) = 0 y 0( ) = 40,y 10( ) = 200
€
p(x) = 0,q(x) = 0.01,r(x) = −0.2α = 40,β = 200
•• Set n=5, h=2Set n=5, h=2
€
−2.04 1 0 01 −2.04 1 00 1 −2.04 10 0 1 −2.04
y1y2y3y4
=
−40.8−0.8−0.8−200.8
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Eigenvalue problemsEigenvalue problems
•• Eigenvalue problems are a special class ofEigenvalue problems are a special class ofboundary-value problemboundary-value problem
•• Common in engineering systems withCommon in engineering systems withoscillating behavioroscillating behavior
–– SpringsSprings
–– ElasticityElasticity
–– RLC circuitsRLC circuits
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Physics of EigenvaluesPhysics of Eigenvalues & Eigenvectors & Eigenvectors
A system of two degrees offreedom.
m1
m2
k2(x2-x1) k3x2
k2(x2-x1)k1x1
To simplify the problem,we assume thatk1= k2= k3= k.
)(
)(
12222
2
2
12121
2
1
xxkkxdt
xdm
xxkkxdt
xdm
−−−=
−+−=
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Physics of Physics of Eigenvalues Eigenvalues (continued)(continued)
Both masses (m1& m2) are oscillating w.r.t. their mean positions.
€
xi = Bi sin(ωt) i = 1 or 2.
d2xi
dt 2= −ω 2Bi sin(ωt) i = 1 or 2.
Substituting the above equations into the motion equations and dividing both sides by
€
−ω 2m1B1 = −kB1 + k(B2 − B1)
−ω 2m2B2 = −kB2 − k(B2 − B1)
€
2km1
−ω 2 −km1
−km2
2km2
−ω 2
B1B2
= 0
. )sin t(ω
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Physics of Physics of Eigenvalues Eigenvalues (continued)(continued)
€
2km1
−km1
−km2
2km2
B1B2
=ω 2 B1B2
€
A[ ] x{ } = λ x{ }
Hence, the eigenvalues are related to the natural frequencies or periods which are crucial to the design of structures.The eigenvectors are related to the motion of a structure related to the corresponding natural frequency.For most engineering problems, the largest or the smallestfrequencies are the most important ones to know.
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Steps of Solving Steps of Solving EigenEigen-value Problems-value Problems
• leads to an algebraic equation of .
•Solving the equation for . - Polynomial method (find roots of an equation) - Other methods (more efficient): Power Method.
•Given the eigenvalues , obtain the correspondingeigenvectors .
€
det A − λI[ ] = 0 . λ
λ
λ{ }x
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Eigenvalue ExampleEigenvalue Example
€
m1 = m2 = 40,k = 200
€
10 −ω 2 −5−5 10 −ω 2
B1B2
= 0
€
det A − λI[ ] = 10 −ω 2( ) 10 −ω 2( ) − −5( ) −5( )
= ω 2( )2− 20ω 2 + 75 = 0
€
ω 2 =15 or 5
€
At ω 2 =15, B1 = −B2 and at ω 2 = 5, B1 = B2
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Eigenvalue ExampleEigenvalue Example
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Boundary value eigenvalue problemsBoundary value eigenvalue problems
•• Polynomial MethodPolynomial Method
–– Similar to Finite-Difference MethodSimilar to Finite-Difference Method
•• Power MethodPower Method
–– HotellingHotelling’’s Methods Method
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Power MethodPower Method
The Power Method is an iterative procedure fordetermining the dominant (largest) eigenvalue of thematrix A and the corresponding eigenvector.
Example
€
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
x1x2x3
= λ
x1x2x3
1. Guess a solution for the eigenvector , x1 =1, x2 =1, x3 =1.
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Example of Power Method (Continued)Example of Power Method (Continued)
{ } { } 2. and 1 stepsrepeat and
guess theas 101r eigenvecto normalizedcurrent theUsing.3
1
0
1
778.1
778.1
0
778.1
.1-or 1either becomes valueabsolutelargest theofelement that the
so side),-hand-right (ther eigenvecto eapproximat theNormalize .2
778.1
0
778.1
1
1
1
556.3778.10
778.1556.3778.1
0778.1556.3
Eq. of side -hand-left theintor eigenvecto thengsubstituti
=
=
=
−
−−
−
Tx
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Example of Power Method (Continued)Example of Power Method (Continued)
€
substituting the eigenvector into the left -hand - side of Eq.
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
101
=
3.556−3.5563.556
= 3.5561−11
4. Examine the relative error of λ,
εa =λi+1 − λiλi+1
=3.556 −1.778
3.556= 50%.
if εa is greater than the tolerance error, the iteration continues.
Otherwise, the eigenvalue λ, and the eigenvector x{ } are obtained.
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Example of Power Method (Continued)Example of Power Method (Continued)
€
Third Iteration
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
1−11
=
5.333−7.1115.333
= −7.111−0.751
−0.75
εa =−7.111− 3.556
−7.111=150%
€
Fourth Iteration
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
−0.751
−0.75
=
−4.4446.222−4.444
= 6.222−0.7141
−0.714
εa =6.222 − −7.111( )
6.222= 214%
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Example of Power Method (Continued)Example of Power Method (Continued)
€
Fifth Iteration
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
−0.7141
−0.714
=
−4.3176.095−4.317
= 6.095−0.7081
−0.708
εa =6.095 − 6.222
6.095= −2.08%
€
The sixth iteration
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
−0.7081
−0.708
=
−4.2966.074−4.296
= 6.074−0.7071
−0.707
εa =6.074 − 6.095
6.074= 0.35%
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Inverse Power MethodInverse Power Method
• The Power Method can be modified to provide thesmallest (lowest) (magnitude) eigenvalue and itseigenvector. The modified method is known as theinverse power method
• The smallest eigenvalue λ in the matrix A corresponds to1/ λ the largest eigenvalue in the inverse matrix A-1.
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
General I-P MethodGeneral I-P Method
The combination of Shifted Power Method and I-P methodcan be use to determine all the eigenvalues and theirrelated eigenvectors.
•Deflation Hotelling’s Method for symmetric matrices•First, normalize the largest eigenvector found by thesum of the squares of the elements in the eigenvector
€
X{ } =X{ }
xk2
k=1
n
∑
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
General I-P MethodGeneral I-P Method
•• Then create new AThen create new A22 matrix matrix
€
A[ ]2 = A[ ]1 − λ1 X{ }1 X{ }1T
€
A[ ]2 X{ } j = A[ ]1 X{ } j − λ1 X{ }1 X{ }1T X{ } j
€
A[ ]2 X{ } j = λ j X{ } j j ≠1A[ ]2 X{ }1 = A[ ]2 X{ }1 − λ1 X{ }1 j =1
•• The new AThe new A22 matrix has the same matrix has the sameeigenvalues as before except that theeigenvalues as before except that thelargest eigenvalue has been replaced with 0largest eigenvalue has been replaced with 0
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
HotellingHotelling’’s Methods Method
€
A =
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
,λ1 = 6.074,x1 =
−0.7071
−0.707
€
Modified A2
A2 =
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
− 6.074−0.7071
−0.707
−0.707 1 −0.707{ }
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
HotellingHotelling’’s Methods Method
€
A2 =
3.556 −1.778 0−1.778 3.556 −1.7780 −1.778 3.556
− 6.0740.5 −0.707 0.5
−0.707 1 −0.7070.5 −0.707 0.5
€
A2 =
0.519 2.516 −3.0372.516 −2.518 2.516−3.037 2.516 0.519
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Exam 2Exam 2
•• Parts 4, 6, and 7 of bookParts 4, 6, and 7 of book
•• OptimizationOptimization
•• Numerical Integration and DifferentiationNumerical Integration and Differentiation
•• Ordinary Differential EquationsOrdinary Differential Equations
ECE 257 Numerical Methods and Scientific Computing
Fall 2004
Lecture 19
John A. Chandy
Dept. of Electrical and Computer Engineering
University of Connecticut
Next LectureNext Lecture
•• Partial Differential EquationsPartial Differential Equations
•• Read Chapter PT8, 29Read Chapter PT8, 29
•• HW6 due 11/16HW6 due 11/16
•• Exam 2 11/9Exam 2 11/9