Stability of Euler’s explicit method.
Consider the solution of the ODE:
dxdy=−2.5y, with y(0)=1, for 0<x<3.4 (10.199)
(a) Solve with Euler’s explicit method using h=0.2.
(b) Solve with Euler’s explicit method using h=0.85.
The exact (analytical) solution is: y=e−2.5x. Show the results from parts (a) and (b) in a plot together with the exact solution.
Equation (10.199) is in the form of Eq. (10.195)
dxdy=−αy, with y(0)=1 (10.195)
with α=2.5. According to Eq. (10.198),
0 < αh< 2 (10.198)
a stable solution will be obtained for h<2.52=0.8. Consequently, it can be expected that a stable solution will be obtained in part (a), while the solution in part (b) will be unstable. The solutions are carried out by writing the following MATLAB program in a script file.
a = 0; b = 3.4; alpha = 2.5;
ha = 0.2; hb = 0.85;
xa(1) = a; xb(1) = a;
ya(1) = 1; yb(1) = 1;
Na = (b - a)/ha; Nb= (b - a)/hb;
DY = @ (y) -2.5*y;
for i = 1:Na
xa(i + 1) = xa(i) + ha;
ya(i + 1) = ya(i) + DY(ya(i))*ha;
end
for i = 1:Nb
xb(i + 1) = xb(i) + hb;
yb(i + 1) = yb(i) + DY(yb(i))*hb;
end
xTrue = a:0.05:b;
yTrue = exp(-alpha*xTrue);
plot(xa,ya, 'ro--' ,xb,yb, '*r--' ,xTrue,yTrue, ' k ' )
The figure generated by the program is shown on the right. As expected, the figure shows that a stable solution is obtained in part (a), while an unstable solution, in which the values of y grow with every step, is obtained in part (b).