



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Numerical Computing S’09 MATH/CSCI 4800- Homework-
Due Tuesday April 28, 2009 by 5 PM
Illegible reports will be returned without grading. Show all work. All Matlab scripts, Matlab output and plots should be printed out and stapled to the report.
(a) The ODE is y′^ + 2y = 4t. The complementary function is ce−^2 t^ and a particular solution is 2t − 1 , yielding the general solution y = ce−^2 t^ + 2t − 1. The initial condition y(0) = 0 determines c to be 1. Then the desired solution to the IVP is y = e−^2 t^ + 2t − 1.
(b) Euler’s method is yn+1 = yn + hf (tn, yn). Here, f (t, y) = − 2 y + 4t whence
yn+1 = yn + h[− 2 yn + 4tn] = (1 − 2 h)yn + 4htn.
This is a linear difference equation. It has a particular solution 2tn − 1. The homogeneous solution is yn = crn^ with r = 1 − 2 h. Therefore the general solution is
yn = c(1 − 2 h)n^ + 2tn − 1.
The initial condition y 0 = 0 determines c = 1, so that
yn = (1 − 2 h)n^ + 2tn − 1.
When specialized to h = 1/4 the above simplifies to
yn =
2 n^
n 2
and yields the following:
y 1 = 0, y 2 = 0. 25 , y 3 = 0. 625 , y 4 = 1. 0625.
The exact solution at the final time is y(1) = e−^2 + 1. Then the (global) error at t = 1 is
y(1) − y 4 = e−^2 + 1 − 1 .0625 = 0. 0728.
0 0.02 0.04 0.06 0.08 0. 0
h
error
Global Error of Euler solution against h
Figure 1: Problem 2, error at t = 1 plotted against h.
(a) The trapezoid method is
yn+1 = yn +
h 2
f (tn, yn) + f
tn + h, yn + hf (tn, yn)
Applied to the given IVP, it reduces to
yn+1 = yn(1 − 2 h + 2h^2 ) + 4h(1 − h)tn + 2h^2.
The solution of this difference equation, subject to y 0 = 0, is
yn = (1 − 2 h + 2h^2 )n^ + 2tn − 1.
(The details follow those in problem 1 above.) For h = 1/4 and tn = nh = n/4 it reduces to
yn =
)n
n 2
and yields the following:
y 1 =
= 0. 1250 , y 2 =
= 0. 3906 , y 3 =
= 0. 7441 , y 4 =
The exact solution at the final time t = 1 is y(1) = e−^2 + 1, giving the global error
y(1) − y 4 = e−^2 + 1 − 1 .1526 = − 0. 0173.
(b) The second-order Taylor method is
yn+1 = yn + hfn + h^2 2
[ft + f fy ]n.
For the given ODE, f = 4t − 2 y, ft = 4, fy = − 2 , and the method reduces to
yn+1 = yn + h(4tn − 2 yn) +
h^2 2
[4 − 2(4tn − 2 yn)]
= yn(1 − 2 h + 2h^2 ) + 4h(1 − h)tn + 2h^2.
This is precisely the same as the trapezoid method discussed in part (a) above, and the same results apply. (This agreement of the two methods is a coincidence, and does not hold in general.)
The system of equations is dy dt
= f (t, y), y(0) =
Here, y =
y 1 y 2
, f =
y 1 + 3y 2 2 y 1 + 2y 2
The exact solution is y(t) =
3 e−t^ + 2e^4 t − 2 e−t^ + 2e^4 t
The trapezoid method, in vector form, is
yn+1 = yn + h 2
f (tn, yn) + f
tn + h, yn + hf (tn, yn)
or, writing the equations separately,
y (^1) n+1 = y (^1) n +
h 2
f 1 (tn, y (^1) n , y (^2) n ) + f 1 (tn + h, y (^1) n + hf 1
tn, y (^1) n , y (^2) n ), y (^2) n + hf 2 (tn, y (^1) n , y (^2) n )
y (^2) n+1 = y (^2) n +
h 2
f 2 (tn, y (^1) n , y (^2) n ) + f 2 (tn + h, y (^1) n + hf 1
tn, y (^1) n , y (^2) n ), y (^2) n + hf 2 (tn, y (^1) n , y (^2) n )
In our case we have f 1 (t, y 1 , y 2 ) = y 1 + 3y 2 , and f 2 (t, y 1 , y 2 ) = 2y 1 + 2y 2. We also have h = 1/ 4. Then the above equations reduce to
y (^1) n+1 = y (^1) n +
{y (^1) n + 3y (^2) n } + y (^1) n + (1/4)(y (^1) n + 3y (^2) n ) + 3{y (^2) n + (1/4)(2y (^1) n + 2y (^2) n )}
y (^2) n+1 = y (^2) n +
{ 2 y (^1) n + 2y (^2) n } + 2{y (^1) n + (1/4)(y (^1) n + 3y (^2) n )} + 2{y (^2) n + (1/4)(2y (^1) n + 2y (^2) n )}
The above equations can be used to construct the solutions at times t = 1/ 4 , 1 / 2 , 3 /4 and 1. The results at these four times are given below in column form. [ y 1 y 2
The error at the last time step is found to be [ y 1 (1) − y 14 = 31. 0574 y 2 (1) − y 24 = 31. 0806
The computation was done on Matlab; see the attached Log.