Preface


This section is devoted to the modified Euler method.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the course APMA0330
Return to the main page for the course APMA0340
Return to Part III of the course APMA0330

Modified Euler method / Midpoint Method


The Modified Euler’s method is also called the midpoint approximation. This method reevaluates the slope throughout the approximation. Instead of taking approximations with slopes provided in the function, this method attempts to calculate more accurate approximations by calculating slopes halfway through the line segment. The syntax of the Modified Euler’s method involves the sum of the current y term and the product of h with the function in terms of the sum of the current x and half of h (which defines the x value) and the sum of the current y and the product of the h value and the function in terms of the current x and y values (which defines the y value).

The midpoint method can be shown to have a local error of 2, so it is second-order accurate. The midpoint method is implemented in NDSolve as "ExplicitMidpoint":

NDSolve[{y'[t] == t^2 - y[t], y[0] == 1}, y[t], {t, 0, 2}, Method -> "ExplicitMidpoint", "StartingStepSize" -> 1/10]

Modified Euler formula or explicit midpoint rule or midpoint Euler algorithm:

\begin{equation} y_{n+1} = y_n +h f\left( x_n + \frac{h}{2}\ , \ y_n + \frac{h}{2} \,f( x_n , y_n ) \right) , \qquad n=0,1,2,\ldots . \end{equation}
Therefore, the Mathematica syntax is as follows:
y[n+1] = y[n]+ h f[x[n]+h/2,y[n] + (h/2)*f[x[n],y[n]]]

Another option:

f[x_, y_] := Exp[2*x - y]
h = 0.1
K = IntegerPart[1.2/h]  (* if the value at x=1.2 needed *)
y[0] = 1                      (* initial condition *)

Then implement modified Euler method/ midpoint rule:

Do[y[k + 1] = y[k] + h*f[k*h + h/2, y[k] + (h/2)*f[k*h, y[k]]], {k, 0, K}]
   y[K]

Example: Consider the initial value problem for the linear equation

\[ \frac{{\text d}y}{{\text d}x} = x\,y - x^2 , \qquad y(0) = 1. \]
   ■

Example: Consider the initial value problem for the logistic equation

\[ \frac{{\text d}y}{{\text d}t} = y\left( 3 - y \right) , \qquad y(0) = 1. \]
   ■

Example: Consider the initial value problem \( y'= 1/(3x-2y+1),\quad y(0)=0 \)

   ■

Let’s take all of the approximations and the exact values to compare the accuracy of the approximation methods:

x values Exact Euler Backwards Euler Trapezoid Improved Euler Modified Euler
0.1 1.049370088 1.050000000 1.057930422 1.0493676 1.049390244 1.049382716
0.2 1.097463112 1.098780488 1.118582822 1.0974587 1.097594738 1.097488615
0.3 1.144258727 1.146316720 1.182399701 1.1442530 1.144322927 1.144297185
0.4 1.189743990 1.192590526 1.249960866 1.1897374 1.189831648 1.189795330
0.5 1.233913263 1.237590400 1.322052861 1.2339064 1.234025039 1.233977276
0.6 1.276767932 1.281311430 1.399792164 1.2767613 1.276904264 1.276844291
0.7 1.318315972 1.323755068 1.484864962 1.3183102 1.318477088 1.318404257
0.8 1.358571394 1.364928769 1.580059507 1.3585670 1.358757326 1.358671110
0.9 1.397553600 1.404845524 1.690720431 1.3975511 1.397764204 1.397664201
1.0 1.435286691 1.443523310 1.830688225 1.4352865 1.435521666 1.435407596
Accuracy N/A 99.4261% 72.4513% 99.9999% 99.9836% 99.9916%

 

 

Return to Mathematica page
Return to the main page (APMA0330)
Return to the Part 1 (Plotting)
Return to the Part 2 (First Order ODEs)
Return to the Part 3 (Numerical Methods)
Return to the Part 4 (Second and Higher Order ODEs)
Return to the Part 5 (Series and Recurrences)
Return to the Part 6 (Laplace Transform)
Return to the Part 7 (Boundary Value Problems)