Matematik och Datavetenskap, Chalmers Tekniska Högskola och Göteborgs Universitet

ALA-B, 2003, studio 4.2

Home, w 1, w 2, w 3, w 4, w 5, w 6, w 7. Matlab: analysis, linear algebra, facit.

My ode solver 2

1. Read AMBS Ch 40.7. In this studio exercise you will modify your program my_ode.m so that it uses the midpoint method instead of the Euler forward method.

First use my_ode.m to solve the system

w'=Aw,    a<t<b,
w(0)=w0

where w=[u; u'], w0=[0; 1], A=[0 1; -1 0]. Use a rather large step (h=1e-1).

Plot the solution

figure(1)
plot(t,W) % solution curves

figure(2)
plot(W(:,1),W(:,2)) % phase plane plot
axis equal

Note that the amplitude is increasing. The reason for this is that the Euler forward method does not conserve the energy in this equation. Instead the energy is increasing.

2. The Euler forward method solves the initial value problem for a general system of ordinary differential equations:

u'(t)=f(t,u(t)),     a< t <b,
u(a)=ua,

by the algorithm

U(ti)=U(ti-1)+h f(ti-1,U(ti-1))

The midpoint method is

U(ti) =U(ti-1)+h f( ( ti-1+ti)/2, ( U(ti-1)+U(ti) )/2)

Note that this is a fixed point equation for V=U(ti), of the form V=g(V):

V =U(ti-1)+h f( ( ti-1+ti)/2, ( U(ti-1)+V )/2)

This equation has a unique solution if the Lipschitz constant of g is smaller than 1, Lg = h Lf/2 < 1, that is, if h < 2/ Lf.

Implement the corresponding fixed point iteration in a new program my_ode2.m:

Vk =U(ti-1)+h f( ( ti-1+ti)/2, ( U(ti-1)+Vk-1 )/2)

Use the tolerance for the iteration tol=h^3. See my program my_ode2.m, if you need a hint.

3. Now solve the system for the trigonometric functions again. Does the amplitude increase?

4. Advanced.
a. Write a program for the Euler backward method. See my program my_ode1.m, if you need a hint.
b. Use Newton's method instead of fixed point iteration.
c. Choose the step adaptively.
Hints: see the ode programs in facit.

/stig


Last modified: Sun Nov 16 20:47:31 MET 2003