Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Stability Stepsize Restriction for Euler’s Method Applied to a Stiff IVODE

• IVODE: y’(t) = -1000 (y(t) – sin(t)) + cos(t), y(0)=1.

• Exact solution: y(t) = e-1000t + sin(t)

• At t=0, the first term is 1 and the second term is 0; as soon as t increases, the first term
quickly becomes 0 and then only the second term is present.

• Plot of solution on [0, 0.05]

• Plot of solution on [0, 8]

• Away from a very small layer region near 0, the exact solution looks like sin(t).
• Looks like Euler’s method should have no problem with this simple looking solution.

• Here is a Scliab script that uses Euler’s method to solve this problem. We will step from
0 to 8 with a step size of 0.1. That will give us a good sense of what the solution is.

// Simple implementation of Euler's Method


// for y'= -1000*(y-sin(t)) + cos(t), y(0)=1, with stepsize 0.1 to
// final time tfinal = 0.3. (Exact solution = exp(-1000*t) + sin(t)).
// Stiff ODE

function f=stiff(t,y); f= -1000*(y-sin(t)) + cos(t); endfunction

t=0; y=1; h=0.1; tfinal= 8; i=1; tt(i) = t; yy(i) = y;

while t < tfinal y = y + h*stiff(t,y); t = t+h; i = i + 1; tt(i) = t; yy(i) = y; end

// Compute the error


ee = yy-(exp(-1000*tt) + sin(tt));

• Here is the error vector, ee:

0.
- 98.999833
9800.9842
- 970297.43
96059446.
- 9.510D+09
9.415D+11
.
.
.
5.69D+111
- 5.63D+113
5.58D+115
- 5.52D+117
5.47D+119
- 5.41D+121

• Whoops!
• Let’s try again with a step size h = 0.05.
ee =

0.
- 48.999979
2400.9991
- 117648.95
5764798.7
- 2.825D+08
.
.
.
- 2.29D+265
1.12D+267
- 5.51D+268
2.70D+270
- 1.32D+272

• . Let’s try h = 0.025.

ee =

ee =

0.
- 23.999997
575.99995
- 13823.999
331775.97
- 7962623.3
1.911D+08
.
.
.
- 1.84D+302
4.43D+303
- 1.06D+305
2.55D+306
- Inf
Nan
Nan
Nan
Nan
.
.
.

• !! Let’s try h = 0.0125.

• The results turn out to similar.

• It turns out that by reducing the step size to be much smaller than you would expect
that you would need to compute a numerical solution that is (basically) sin(t), one can
obtain good results.

• With h = 0.001, the solution looks like

• Why does h have to be so small, given how simple the solution looks?

You might also like