Docsity

Math128B HW8: Nonlinear Shooting & Finite Difference Methods for ODEs, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
1
Math128B
Mar. 21, 2005
Jonathan Dorfman
Homework 8 Solutions
Problem 8.1 & 8.2
file function
Hmwk8Main.m calls NLShooting to solve BVP: y00(t) = −y02−y+ log x, x ∈[1,2],y (1) = 0, y(2) = log2
calls NLFiniteDiff to solve BVP: y00(t) = −y02−y+ log x, x ∈[1,2], y(1) = 0, y(2) = log 2
compares with exact solution y(x) = log x
NLShooting.m calls NLRungeKutta4 adapted to nonlinear method requiring y-values
implements p.654-656 of Burden & Faires
NLFiniteDiff.m implements p.667-668 of Burden & Faires
NLRungeKutta4.m implements p. 519 of Mathews & Fink (Program 9.9 with NonLinear modifications)
DF8 1.m implement specifics of ODE y00(t) = −y02−y+ log x(Eq. (11.6) p.653)
DF8 1z.m implement specifics Jacobian for ODE y00(t) = −y02−y+ log x(Eq. (11.12) p.656)
DF8 2.m implement specifics of ODE y00(t) = −y02−y+ log x(Eq. (11.6) p.653)
DF8 2Jac.m implement specifics of Jacobian for ODE y00(t) = −y02−y+ log x(Eq. (11.20) p.668)
A diary of the output follows:
least squares error in Nonlinear Shooting Method with h=0.1 is 2.2827e-006
least squares error in Nonlinear Finite Difference Method with h=0.1 is 0.00012761
Example of graphical output:
1.8231 1.8231 1.8231 1.8231 1.8231 1.8231
0.6003
0.6003
0.6003
0.6003
0.6003
0.6003
0.6003
0.6003
0.6003
0.6003
y’’(x) = − y’(x)2 − y(x) + log(x)
y’’(x) = − y’(x)2 − y(x) + log(x)
y(1)=0, y’(2)=log(2)
x∈[1,2], h=0.1
NonLinear Shooting with h=0.1
Exact
pf3

Partial preview of the text

Download Math128B HW8: Nonlinear Shooting & Finite Difference Methods for ODEs and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Math128B

Mar. 21, 2005 Jonathan Dorfman Homework 8 Solutions

Problem 8.1 & 8.

file function Hmwk8Main.m calls NLShooting to solve BVP: y′′(t) = −y′^2 − y + log x, x ∈ [1, 2], y(1) = 0, y(2) = log 2 calls NLFiniteDiff to solve BVP: y′′(t) = −y′^2 − y + log x, x ∈ [1, 2], y(1) = 0, y(2) = log 2 compares with exact solution y(x) = log x NLShooting.m calls NLRungeKutta4 adapted to nonlinear method requiring y-values implements p.654-656 of Burden & Faires NLFiniteDiff.m implements p.667-668 of Burden & Faires NLRungeKutta4.m implements p. 519 of Mathews & Fink (Program 9.9 with NonLinear modifications) DF8 1.m implement specifics of ODE y′′(t) = −y′^2 − y + log x (Eq. (11.6) p.653) DF8 1z.m implement specifics Jacobian for ODE y′′(t) = −y′^2 − y + log x (Eq. (11.12) p.656) DF8 2.m implement specifics of ODE y′′(t) = −y′^2 − y + log x (Eq. (11.6) p.653) DF8 2Jac.m implement specifics of Jacobian for ODE y′′(t) = −y′^2 − y + log x (Eq. (11.20) p.668) A diary of the output follows:

least squares error in Nonlinear Shooting Method with h=0.1 is 2.2827e-

least squares error in Nonlinear Finite Difference Method with h=0.1 is 0.

Example of graphical output:

1.8231 1.8231 1.8231 1.8231 1.8231 1.

y’’(x) = − y’(x)^2 − y(x) + log(x)

y’’(x) = − y’(x)^2 − y(x) + log(x) y(1)=0, y’(2)=log(2) x∈[1,2], h=0.

NonLinear Shooting with h=0. Exact

Example of graphical output:

1.792 1.7921 1.7921 1.7922 1.7922 1.7923 1.7923 1.7924 1.7924 1.

y’’(x) = − y’(x)^2 − y(x) + log(x)

y’’(x) = − y’(x)^2 − y(x) + log(x) y(1)=0, y’(2)=log(2) x∈[1,2], h=0.

NonLinear Finite Difference with h=0. Exact

Problem 8.

(a) Letting u(x, t) = sin(n π x) cos(c n π t) we compute:

ux = +nπ cos(n π x) cos(c n π t) uxx = −n^2 π^2 sin(n π x) cos(c n π t) ut = −c nπ sin(n π x) sin(c n π t) utt = −c^2 n^2 π^2 sin(n π x) cos(c n π t) utt − c^2 uxx = 0

Alternatively, using the trig identity sin A cos B = 12 sin(A + B) + 12 sin(A − B) we could rewrite the above as: u(x, t) = 12 sin(nπx + cnπt) + 12 sin(nπx − cnπt)

Since this expression for u(x, t) has the D’Alembert form (see Eqn. (14) p. 549 of Mathews & Fink)

u(x, t) = F (x + ct) + G(x − ct) where F (z) = G(z) = 12 sin(n π z)

we conclude it must solve the wave equation.

(b) We have by Eqn. (12.18) on p. 719 of Burden & Faires (or Eqn. (7) p. 550 of Mathews & Fink):

wi,j+1 = 2(1 − λ^2 )wi,j + λ^2 (wi+1,j + wi− 1 ,j ) − wi,j− 1 where λ = αk/h

Therefore, by setting λ = 1 we see that the above expression for wi,j+1 reduces to:

wi,j+1 = (wi+1,j + wi− 1 ,j ) − wi,j− 1

as required by the exercise (see also Eqn. (17) p. 550 of Mathews & Fink). Since in the present case α =

9 = 3 (utt − α^2 uxx = utt − 9 uxx = 0 - Eqn (12.16)) , we get 1 = λ = αk/h = 3k/h whence h = 3k.