Docsity

Applied Numerical Methods - Homework 2 with Solutions | MATH 151A, Assignments of Mathematics

Toggle sidebar
bg1
Homework 2 Solutions
Igor Yanovsky (Math 151B TA)
Section 5.3, Problem 1(b): Use Taylor’s method of order two to approximate the
solution for the following initial-value problem:
y0= 1 + (t−y)2,2≤t≤3,
y(2) = 1,(1)
with h= 0.5.
Solution: Let us first derive the Taylor’s method or order two for general initial value
problem
y0=f(t, y), a ≤t≤b,
y(a) = α. (2)
Expand the solution y(t) in terms of its second Taylor polynomial about tiand evaluate
at ti+1, we obtain
y(ti+1) = y(ti) + hy0(ti) + h2
2y00(ti) + h3
6y000(ξi),(3)
for some ξi∈(ti, ti+1). Since we have y0(t) = f(t, y(t)), differentiating y0(t) twice gives
y00(t) = f0(t, y(t)),
y000(t) = f00(t, y (t)).
Plugging these into (3) gives
y(ti+1) = y(ti) + hf (ti, y(ti)) + h2
2f0(ti, y(ti)) + h3
6f00(ξi, y(ξi)).(4)
When his small, the last term in (4) is small, and thus, we can ignore it. The Taylor’s
method of order two for general initial value problem (2) is therefore
w0=α,
wi+1 =wi+hf(ti, wi) + h2
2f0(ti, wi).(5)
For the initial value problem (1), we have
f(t, y(t)) = 1 + (t−y)2,
f0(t, y(t)) = d
dt(1 + (t−y)2) = 2(t−y)·(1 −y0) = 2(t−y)·(1 −(1 + (t−y)2))
=−2(t−y)3.
Equation (5), with ti= 2 + 0.5i, becomes
wi+1 =wi+h(1 + (ti−wi)2)−h2
2(2(ti−wi)3)
=wi+ 0.5(1 + (2 + 0.5i−wi)2)−0.25(2 + 0.5i−wi)3.
1
pf3
pf4
pf5

Partial preview of the text

Download Applied Numerical Methods - Homework 2 with Solutions | MATH 151A and more Assignments Mathematics in PDF only on Docsity!

Homework 2 Solutions

Igor Yanovsky (Math 151B TA)

Section 5.3, Problem 1(b): Use Taylor’s method of order two to approximate the solution for the following initial-value problem:

y′^ = 1 + (t − y)^2 , 2 ≤ t ≤ 3 , y(2) = 1,

with h = 0.5.

Solution: Let us first derive the Taylor’s method or order two for general initial value problem

y′^ = f (t, y), a ≤ t ≤ b, y(a) = α.

Expand the solution y(t) in terms of its second Taylor polynomial about ti and evaluate at ti+1, we obtain

y(ti+1) = y(ti) + hy′(ti) +

h^2 2 y′′(ti) +

h^3 6 y′′′(ξi), (3)

for some ξi ∈ (ti, ti+1). Since we have y′(t) = f (t, y(t)), differentiating y′(t) twice gives

y′′(t) = f ′(t, y(t)), y′′′(t) = f ′′(t, y(t)).

Plugging these into (3) gives

y(ti+1) = y(ti) + hf (ti, y(ti)) + h^2 2 f ′(ti, y(ti)) + h^3 6 f ′′(ξi, y(ξi)). (4)

When h is small, the last term in (4) is small, and thus, we can ignore it. The Taylor’s method of order two for general initial value problem (2) is therefore

w 0 = α, wi+1 = wi + hf (ti, wi) + h^2 2

f ′(ti, wi).

For the initial value problem (1), we have

f (t, y(t)) = 1 + (t − y)^2 ,

f ′(t, y(t)) =

d dt (1 + (t − y)^2 ) = 2(t − y) · (1 − y′) = 2(t − y) · (1 − (1 + (t − y)^2 )) = −2(t − y)^3.

Equation (5), with ti = 2 + 0. 5 i, becomes

wi+1 = wi + h(1 + (ti − wi)^2 ) −

h^2 2 (2(ti − wi)^3 ) = wi + 0.5(1 + (2 + 0. 5 i − wi)^2 ) − 0 .25(2 + 0. 5 i − wi)^3.

Hence, with w 0 = 1, we have

w 1 = w 0 + 0.5(1 + (2 − w 0 )^2 ) − 0 .25(2 − w 0 )^3 = 1 + 0.5(1 + 1) − 0 .25 = 1. 75 , X w 2 = w 1 + 0.5(1 + (2 + 0. 5 − w 1 )^2 ) − 0 .25(2 + 0. 5 − w 1 )^3 = 1 .75 + 0.5(1 + (2 + 0. 5 − 1 .75)^2 ) − 0 .25(2 + 0. 5 − 1 .75)^3 = 2. 425781. X

Section 5.3, Problem 1(c): Use Taylor’s method of order two to approximate the solution for the following initial-value problem:

y′^ = 1 + y t , 1 ≤ t ≤ 2 , y(1) = 2,

with h = 0.25.

Solution: The Taylor’s method of order two for general initial value problem (2) is given by equation (5). For the initial value problem (6), we have

f (t, y(t)) = 1 + y t

f ′(t, y(t)) =

d dt

y t

y′t − y t^2

(1 + yt )t − y t^2

t

Equation (5), with ti = 1 + 0. 25 i, becomes

wi+1 = wi + h

wi ti

h^2 2

ti

= wi + 0. 25

wi 1 + 0. 25 i

1 + 0. 25 i

Hence, with w 0 = 2, we have

w 1 = w 0 + 0.25(1 + w 0 ) + 0.03125 = 2. 78125 , X w 2 = w 1 + 0. 25

w 1

  1. 25

= 3. 6125 , X

and, similarly, calculate w 3 and w 4.

b) The formula for calculating the global error is located on page 327 of the textbook:

|y(ti) − wi| ≤ τ (h) L

eL(ti−a),

where τi(h) satisfies τi(h) ≤ τ (h). Since y′′(t) = −4 cos t − 42(t − 4), we have

|y′′(t)| ≤ | − 4 cos t − 42(t − 4)| ≤ 250 .4 = M,

which gives

|τ (h)| ≤

h 2

M =

Thus, the global error is

|y(ti) − wi| ≤

· e2(3+2)^ = 1379. X

Problem 3: Use the midpoint method to approximate the solution to the initial value problem

y′^ = 1 + (t − y)^2 , 2 ≤ t ≤ 3 , y(2) = 1,

with stepsize h = 0.5. The exact solution is y(t) = t +

1 − t

. Compare the approximate

and exact solutions.

Solution: The Runge-Kutta Midpoint method for the solution of the initial value problem

y′^ = f (t, y), a ≤ t ≤ b, y(a) = α, (9)

can be written as

w 0 = α, wi+1 = wi + hf

ti + h 2

, wi + h 2

f (ti, wi)

, i = 0, 1 ,....

For the initial value problem in (8), ti = 2 + ih, i.e. t 0 = 2. 0 , t 1 = 2. 5 , t 2 = 3.0, and we need to take only two steps, calculating w 1 at time t 1 , and w 2 at time t 2. We have:

w 0 = 1 , (11)

w 1 = w 0 + hf

t 0 + h 2

, w 0 + h 2

f (t 0 , w 0 )

= 1 + 0. 5 f

2 + 0. 25 , 1 + 0.25(1 + (2 − 1)^2 )

= 1 + 0. 5 f (2. 25 , 1 .5) (14) = 1 + 0. 5 · (1 + (2. 25 − 1 .5)^2 ) = 1. 78125 , (15)

w 2 = w 1 + hf

t 1 + h 2 , w 1 + h 2 f (t 1 , w 1 )

= 1 .78125 + 0. 5 f

2 .5 + 0. 25 , 1 .78125 + 0. 25 f (2. 5 , 1 .78125)

= 1 .78125 + 0. 5 f

2. 75 , 1 .78125 + 0. 25 · (1 + (2. 5 − 1 .78125)^2 )

= 1 .78125 + 0. 5 f (2. 75 , 2 .16040) (19) = 1 .78125 + 0.5(1 + (2. 75 − 2 .16040)^2 ) (20) = 2. 455064. (21)

The exact solution gives the following values: y(t 1 = 2.5) = 1.8333 and y(t 2 = 3) = 2.5. Note that these results are more accurate than the results obtained with Euler’s method in Homework 1.

c) The Runge-Kutta Midpoint method for the solution of the initial value problem

y′^ = f (t, y), a ≤ t ≤ b, y(a) = α,

is

w 0 = α, wi+1 = wi + hf

ti +

h 2 , wi +

h 2 f (ti, wi)

, i = 0, 1 ,....

Running the Runge-Kutta Midpoint method program gives:

N = 8591, h = 1. 1640088 e − 004 , t = 2. 00 , w = 5. 3862943603 e + 000, y = 5. 3862943611 e + 000 , error = 8. 5053120102 e − 010. Thus, RK Midpoint rule gives considerably more accurate results than Euler’s method.

d) Running the Midpoint program gives the following results:

N = 17182, h = 5. 8200442 e − 005 , t = 2. 00 , w = 5. 3862943609 e + 000, y = 5. 3862943611 e + 000 , error = 2. 0656898414 e − 010.

Order of convergence:

p =

log 10

( (^) wh−yexact wh/ 2 −yexact

log 10 (2.0)

log 10

( (^8). 5053120102 e− 010

  1. 0656898414 e− 010

log 10 (2.0)

≈ 2. 041. X

We obtain the 2rd, or quadratic, order of convergence, for the second order Runge-Kutta Midpoint method, which is expected.