Docsity

Assignment 5 Solutions for Numerical Computing | MATH 4800, Assignments of Mathematics

Toggle sidebar
bg1
Numerical Computing F’05 A. Kapila
Assignment 5 Solutions
1. (Pencil-and-paper, mostly)
(a) i. Describe in words the distinction between a stable and an unstable solution of an ODE. State
a mathematical criterion for determining the stability of a solution. Can the stability or
instability of a solution change with time?
ii. Classify each of the following ODEs as having unstable, stable or asymptotically stable solu-
tions.
A. y0= 2y+t.
B. y0= 2y−t.
C. y0=t−2y.
D. y0=t/2.
(b) For the initial-value problem y0=−200ty2, y(0) = 1,compute the solution at t= 0.1 by using
(i) the Euler method, and (ii) the Taylor method of order 2. Show all steps and produce the final
answers as numbers, not formulas.
(a) i. Let a solution y(t) to y0=f(t,y ), t > t0,have a neighboring solution z(t).Then, y(t)
is said to be stable if, given any > 0,there exists a δ > 0 such that |y(t)−z(t)|<
for t > t0if |y(t0)−z(t0)|< δ. In other words, if the two solutions are initially close, they
stay close for all t. The mathematical criterion for stability is ∂f/∂y ≤0.Since ∂f/∂y can
change its value as the solution y(t) evolves, stability can change as well.
ii. A. y0= 2y+t. Here, ∂f /∂ y = 2 >0.Hence unstable.
B. y0= 2y−t. Here, ∂f /∂y = 2 >0.Hence unstable.
C. y0=t−2y. Here, ∂f /∂ y =−2<0.Hence asymptotically stable.
D. y0=t/2.Here, ∂f /∂y = 0.Hence stable.
(b) The Euler algorithm applied to the equation at hand gives
yn+1 =yn+hf(tn, yn)
=yn+h[−200tny2
n]
For n= 0, h = 0.1,one obtains
y1=y0+hf(t0, y0)
= 1 + 0.1[−200 ×0×12] = 1.
The Taylor method of order 2 gives
yn+1 =yn+hf(tn, yn) + h2
2[ft(tn, yn) + f(tn, yn)fy(tn, yn)]
=yn+h[−200tny2
n] + h2
2[−200y2
n+{−200tny2
n}{−400tnyn}]
Then,
y1= 1 + 0.1[−200 ×0×12] + 0.01
2[−200 + 0]
= 0.
2. (Pencil-and-paper, mostly) Consider the initial-value problem y0=−y2, y (0) = 1.We wish to use one
step of the backward Euler method to compute the approximate value of solution at t= 0.1.Since
the method is implicit, and the ODE is nonlinear, we shall need to solve a nonlinear algebraic equation
for y1,the numerical approximation to the solution y(0.1).
pf3
pf4
pf5

Partial preview of the text

Download Assignment 5 Solutions for Numerical Computing | MATH 4800 and more Assignments Mathematics in PDF only on Docsity!

Numerical Computing F’05 A. Kapila Assignment 5 Solutions

  1. (Pencil-and-paper, mostly)

(a) i. Describe in words the distinction between a stable and an unstable solution of an ODE. State a mathematical criterion for determining the stability of a solution. Can the stability or instability of a solution change with time? ii. Classify each of the following ODEs as having unstable, stable or asymptotically stable solu- tions. A. y′^ = 2y + t. B. y′^ = 2y − t. C. y′^ = t − 2 y. D. y′^ = t/ 2. (b) For the initial-value problem y′^ = − 200 ty^2 , y(0) = 1, compute the solution at t = 0.1 by using (i) the Euler method, and (ii) the Taylor method of order 2. Show all steps and produce the final answers as numbers, not formulas.

(a) i. Let a solution y(t) to y′^ = f (t, y), t > t 0 , have a neighboring solution z(t). Then, y(t) is said to be stable if, given any  > 0 , there exists a δ > 0 such that |y(t) − z(t)| <  for t > t 0 if |y(t 0 ) − z(t 0 )| < δ. In other words, if the two solutions are initially close, they stay close for all t. The mathematical criterion for stability is ∂f /∂y ≤ 0. Since ∂f /∂y can change its value as the solution y(t) evolves, stability can change as well. ii. A. y′^ = 2y + t. Here, ∂f /∂y = 2 > 0. Hence unstable. B. y′^ = 2y − t. Here, ∂f /∂y = 2 > 0. Hence unstable. C. y′^ = t − 2 y. Here, ∂f /∂y = − 2 < 0. Hence asymptotically stable. D. y′^ = t/ 2. Here, ∂f /∂y = 0. Hence stable. (b) The Euler algorithm applied to the equation at hand gives

yn+1 = yn + hf (tn, yn) = yn + h[− 200 tny^2 n]

For n = 0, h = 0. 1 , one obtains

y 1 = y 0 + hf (t 0 , y 0 ) = 1 + 0.1[− 200 × 0 × 12 ] = 1.

The Taylor method of order 2 gives

yn+1 = yn + hf (tn, yn) +

h^2 2

[ft(tn, yn) + f (tn, yn)fy (tn, yn)]

= yn + h[− 200 tny n^2 ] + h^2 2

[− 200 y n^2 + {− 200 tny^2 n}{− 400 tnyn}]

Then,

y 1 = 1 + 0.1[− 200 × 0 × 12 ] +

[−200 + 0]

  1. (Pencil-and-paper, mostly) Consider the initial-value problem y′^ = −y^2 , y(0) = 1. We wish to use one step of the backward Euler method to compute the approximate value of solution at t = 0. 1. Since the method is implicit, and the ODE is nonlinear, we shall need to solve a nonlinear algebraic equation for y 1 , the numerical approximation to the solution y(0.1).

(a) Write out the nonlinear algebraic equation for y 1. (b) Write out the Newton iteration for solving the nonlinear algebraic equation. (c) Obtain a starting guess for the Newton iteration by using one step of the Euler method. (d) Finally, compute an approximate value for y 1 by using one iteration of Newton’s method for the nonlinear algebraic equation.

(a) The backward-Euler algorithm is

yn+1 = yn + hf (tn+1, yn+1).

Here, f (t, y) = −y^2. Therefore we get

y 1 = y 0 − 0. 1 × y^21 = 1 − 0. 1 × y^21.

Let us denote y 1 by z. Then the above nonlinear algebraic equation becomes

F (z) ≡ z − 1 + 0. 1 z^2 = 0. (1)

(b) The Newton iteration for solving this nonlinear system is

zn+1 = zn −

F (zn) F ′(zn)

= zn −

zn − 1 + 0. 1 z^2 n 1 + 0. 2 zn

1 + 0. 1 z n^2 1 + 0. 2 zn

(c) One step of the Euler method gives

y 1 = y 0 + hf (t 0 , y 0 ).

Here, y 1 = 1 + 0.1(−1) = 0. 99. We take this value as z 0 , the starting guess for the Newton iteration (2). (d) The next iterate in Newton’s method is, from (2),

z 1 =

1 + 0. 1 z^20 1 + 0. 2 z 0 =

  1. (Matlab) Consider the initial-value problem

dy dt

= λy + (1 − λ) cos t − (1 + λ) sin t, y(0) = 1.

Its exact solution is independent of λ, and is sin t + cos t. Consider the numerical solution of this problem. Write a Matlab script that solves the above problem by using both the Euler method and the Taylor method of order 2, on the interval t ∈ [0, 5].. The script eulertaylor.m, and the associated function file odetaylor.m may be useful for this purpose. Keep in mind that these scripts will need to be modified in order to answer the following questions.

(a) For λ = 1, solve the problem numerically for h = 1/ 10 , 1 / 20 , 1 / 40 , 1 / 80 , 1 / 160 , and 1/ 320. Plot the exact solution and the Euler and Taylor numerical approximations on t ∈ [0, 5]. Plot the global error (i.e., the difference between the exact and numerical solutions) against h for each of the two numerical approximations; it may be best to use the log-log scale. i. What do you observe from the graphs at various h?

% SCRIPTS FOR Problem 3, HW 5

% script eulertaylor22.m

% calls euler and taylor2 and plots results

% along with a plot of the exact solution.

% Also plots global error.

clc

clear

lambda=1;

a=0; b=5; y0=1;

NN=50*[1 2 4 8 16 32];

hh=(b-a)./NN;

eulererror=[]; taylorerror=[];

for j=1:

h=hh(j);

N=NN(j);

x=a+(0:N)*h;

ye(1)=y0; yt(1)=y0;

for k=1:N

[f,fp]=feval('testfun',x(k),ye(k),lambda);

ye(k+1)=ye(k)+h*f; % Euler solution

[f,fp]=feval('testfun',x(k),yt(k),lambda);

yt(k+1)=yt(k)+hf+h^2fp/2; % Taylor2 solution

end

% Plot Euler solution

figure

plot(x,ye,'rx-')

hold on

% Plot Taylor2 solution

plot(x,yt,'bo-')

hold on

% Compute and plot exact solution

xx=linspace(0,5);

y=sin(xx)+cos(xx);

plot(xx,y,'g','linewidth',2)

legend('Euler','Taylor','Exact')

zoom on

% Find global error for each procedure

exact=sin(5)+cos(5);

eulererror=[eulererror,abs(exact-ye(N+1))];

taylorerror=[taylorerror,abs(exact-yt(N+1))];

end

% Plot global errors against h

figure

loglog(hh,eulererror,'rx-',hh,taylorerror,'bo-')

legend('Euler Error', 'Taylor Error')

function [f,fp]=testfun(t,y,lambda)

f=lambday+(1-lambda)cos(t)-(1+lambda)*sin(t);

fp=lambdaf - (1-lambda)sin(t)-(1+lambda)*cos(t);