Solving ODEs Using Euler Methods (Forward, Backward and Modified Euler)

by admin in on April 27, 2019

This code uses three Euler Methods (Forward Euler, Backward Euler, Modified Euler) to Solve single Ordinary Differential Equations (ODE). This code compare between the three methods and presents results on one chart, and shows the Errors also on one chart.

Code Outputs:

• Chart presenting Euler Methods (Forward Euler, Backward Euler, Modified Euler) compared with Exact solution (if exist).
• Error chart (the absolute error between exact and Euler solutions).
• Printed Maximum absolute error for the three methods.

Max. Forward Euler Error = 0.042844
Max. Modified Euler Error = 0.010017
Max. Backward Euler Error = 0.0092826

Input Requirements:

• The differential equation intended to be calculated.
• Integral Terms.
• Initial Conditions.
• Exact solution if exist.
• Number of iterations.

Euler’s method is a numerical method to solve first order first degree differential equation with a given initial value. It is the most basic explicit method for numerical integration of ordinary differential equations and is the simplest Runge–Kutta method. The Euler method is named after Leonhard Euler, who treated it in his book Institutionum calculi integralis (published 1768–1870).

Backward Euler method (or implicit Euler method) is one of the most basic numerical methods for the solution of ordinary differential equations. It is similar to the (standard) Euler method, but differs in that it is an implicit method. The backward Euler method has order one in time.

The Euler method is a first-order method, which means that the local error (error per step) is proportional to the square of the step size, and the global error (error at a given time) is proportional to the step size. The Euler method often serves as the basis to construct more complex methods, e.g., predictor–corrector method.

Forward Euler Method:

The Euler method can be derived in a number of ways. Firstly, there is the geometrical description above. Another possibility is to consider the Taylor expansion of the function y around t0:

The differential equation states that y’ = f(t,y). If this is substituted in the Taylor expansion and the quadratic and higher-order terms are ignored, the Euler method arises. The Taylor expansion is used below to analyze the error committed by the Euler method, and it can be extended to produce Runge–Kutta methods.

A closely related derivation is to substitute the forward finite difference formula for the derivative,

in the differential equation y’ = f(t,y). Again, this yields the Euler method. A similar computation leads to the midpoint method and the backward Euler method.

Finally, one can integrate the differential equation from t0 to t0+h and apply the fundamental theorem of calculus to get:

Now approximate the integral by the left-hand rectangle method (with only one rectangle):

Combining both equations, one finds again the Euler method. This line of thought can be continued to arrive at various linear multistep methods.

Backward Euler Method:

Consider the ordinary differential equation

with initial value y(t0) = y0 Here the function f and the initial data t0 and y0 are known; the function y depends on the real variable t and is unknown. A numerical method produces a sequence y0,y1,y2,… such that yk approximates y(t0 + kh), where h is called the step size.

The backward Euler method computes the approximations using

This differs from the (forward) Euler method in that the latter uses f(tk,yk) in place of f(tk+1,yk+1). The backward Euler method is an implicit method: the new approximation yk+1 appears on both sides of the equation, and thus the method needs to solve an algebraic equation for the unknown yk+1. For non-stiff problems, this can be done with fixed-point iteration:

If this sequence converges (within a given tolerance), then the method takes its limit as the new approximation yk+1. Alternatively, one can use (some modification of) the Newton–Raphson method to solve the algebraic equation.

Integrating the differential equation

from tn to tn+1 = tn + h yields

Now approximate the integral on the right by the right-hand rectangle method (with one rectangle):

Finally, use that yn is supposed to approximate y(tn) and the formula for the backward Euler method follows. The same reasoning leads to the (standard) Euler method if the left-hand rectangle rule is used instead of the right-hand one.

Modified Euler Method:

A simple modification of the Euler method which eliminates the stability problems noted in the previous section is the backward Euler method:

This differs from the (standard, or forward) Euler method in that the function f is evaluated at the end point of the step, instead of the starting point. The backward Euler method is an implicit method, meaning that the formula for the backward Euler method has yn+1 on both sides, so when applying the backward Euler method we have to solve an equation. This makes the implementation more costly.

Other modifications of the Euler method that help with stability yield the exponential Euler method or the semi-implicit Euler method. More complicated methods can achieve a higher order (and more accuracy). One possibility is to use more function evaluations. This is illustrated by the midpoint method which is already mentioned in this article:

This leads to the family of Runge–Kutta methods. The other possibility is to use more past values, as illustrated by the two-step Adams–Bashforth method:

This leads to the family of linear multistep methods. There are other modifications which uses techniques from compressive sensing to minimize memory usage.

References

• Atkinson, Kendall A. (1989). An Introduction to Numerical Analysis (2nd ed.). New York: John Wiley & Sons. ISBN 978-0-471-50023-0.
• Ascher, Uri M.; Petzold, Linda R. (1998). Computer Methods for Ordinary Differential Equations and Differential-Algebraic Equations. Philadelphia: Society for Industrial and Applied Mathematics. ISBN 978-0-89871-412-8.
• Butcher, John C. (2003). Numerical Methods for Ordinary Differential Equations. New York: John Wiley & Sons. ISBN 978-0-471-96758-3.
• Hairer, Ernst; Nørsett, Syvert Paul; Wanner, Gerhard (1993). Solving ordinary differential equations I: Nonstiff problems. Berlin, New York: Springer-Verlag. ISBN 978-3-540-56670-0.
• Iserles, Arieh (1996). A First Course in the Numerical Analysis of Differential Equations. Cambridge University Press. ISBN 978-0-521-55655-2.
• Stoer, Josef; Bulirsch, Roland (2002). Introduction to Numerical Analysis (3rd ed.). Berlin, New York: Springer-Verlag. ISBN 978-0-387-95452-3.
• Lakoba, Taras I. (2012), Simple Euler method and its modifications (PDF) (Lecture notes for MATH334), University of Vermont, retrieved 29 February 2012
• Unni, M P. (2017). Memory reduction for numerical solution of differential equations using compressive sensing. IEEE CSPA. ISBN 978-1-5090-1184-1.

Share Now!

Release Information

• Price
:

\$5.99

• Released
:

April 27, 2019

• Last Updated
:

May 28, 2019