Holooly Plus Logo

Question 10.13: Stability of Euler's explicit method. Consider the solution ......

Stability of Euler’s explicit method.

Consider the solution of the ODE:

\frac{d y}{d x}=-2.5 y, \text { with } y(0)=1, \text { 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.5 x}. Show the results from parts (a) and (b) in a plot together with the exact solution.

The 'Blue Check Mark' means that either the MATLAB code/script/answer provided in the answer section has been tested by our team of experts; or the answer in general has be fact checked.

Learn more on how do we answer questions.

Script File

Equation (10.199) is in the form of Eq. (10.195)

\frac{dy}{dx}= -\alpha y, \text{ with } y(0) = 1 (10.195)

with \alpha=2.5. According to Eq. (10.198),

0 < αh< 2        (10.198)

a stable solution will be obtained for h<\frac{2}{2.5}=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).

10.13

Related Answered Questions