Modified Euler's Method Calculator

Type y' = f(x, y), the starting point, the step size and the end value.

Write y' = f(x, y), such as y' = x + y, or just the right side.

The starting value of x.

The value of y at the start.

The step size, more than 0. The distance from x₀ to the end must be a whole number of steps.

The value of x to stop at, more than x₀. At most 1000 steps.

Try

Result

You enteredy′=x+y,y(0)=1, h=0.1y' = x + y,\quad y(0) = 1,\ h = 0.1

y(0.5)≈1.794894\displaystyle y(0.5) \approx 1.794894

Exact solution

y=2ex−x−1\displaystyle y = 2e^{x} - x - 1

Exact value

y(0.5)=1.797443\displaystyle y(0.5) = 1.797443

Error

∣error∣=0.002549\displaystyle |\text{error}| = 0.002549
Show the work
  1. Modified Euler's method (midpoint)

    Instead of the slope at the start of the step, use the slope at its MIDDLE: take half an Euler step to estimate the midpoint, find the slope there, and use it for the whole step.

    Using yn+1=yn+h f(xn+h2, yn+h2f(xn,yn))y_{n+1} = y_n + h\,f\left(x_n + \tfrac{h}{2},\ y_n + \tfrac{h}{2}f(x_n, y_n)\right)

    k1=f(xn,yn)k2=f(xn+h2, yn+h2k1)yn+1=yn+hk2\begin{gathered} k_1 = f(x_n, y_n) \\ k_2 = f\left(x_n + \tfrac{h}{2},\ y_n + \tfrac{h}{2}k_1\right) \\ y_{n+1} = y_n + h k_2 \end{gathered}
  2. Step 1

    From (x0,y0)=(0,1)(x_0, y_{0}) = (0, 1).

    k1=1, k2=f(0.05, 1.05)=1.1;y1=1+0.1⋅1.1=1.11\begin{gathered} k_1 = 1,\ k_2 = f(0.05,\ 1.05) = 1.1; \\ y_1 = 1 + 0.1\cdot 1.1 = 1.11 \end{gathered}
  3. Step 2

    From (x1,y1)=(0.1,1.11)(x_1, y_{1}) = (0.1, 1.11).

    k1=1.21, k2=f(0.15, 1.1705)=1.3205;y2=1.11+0.1⋅1.3205=1.24205\begin{gathered} k_1 = 1.21,\ k_2 = f(0.15,\ 1.1705) = 1.3205; \\ y_2 = 1.11 + 0.1\cdot 1.3205 = 1.24205 \end{gathered}
  4. Step 3

    From (x2,y2)=(0.2,1.24205)(x_2, y_{2}) = (0.2, 1.24205).

    k1=1.44205, k2=f(0.25, 1.314153)=1.564153;y3=1.24205+0.1⋅1.564153=1.398465\begin{gathered} k_1 = 1.44205,\ k_2 = f(0.25,\ 1.314153) = 1.564153; \\ y_3 = 1.24205 + 0.1\cdot 1.564153 = 1.398465 \end{gathered}
  5. Table of steps

    Every step with its two slopes.

    nxnynk1k2001⋅⋅10.11.1111.120.21.242051.211.320530.31.3984651.442051.56415340.41.5818041.6984651.83338950.51.7948941.9818042.130894\begin{array}{ccccc} n & x_n & y_n & k_1 & k_2 \\ \hline 0 & 0 & 1 & \cdot & \cdot \\ 1 & 0.1 & 1.11 & 1 & 1.1 \\ 2 & 0.2 & 1.24205 & 1.21 & 1.3205 \\ 3 & 0.3 & 1.398465 & 1.44205 & 1.564153 \\ 4 & 0.4 & 1.581804 & 1.698465 & 1.833389 \\ 5 & 0.5 & 1.794894 & 1.981804 & 2.130894 \end{array}
  6. Compare with the exact solution

    This equation has an exact solution, so the numerical value can be checked: y=2ex−x−1y = 2e^{x} - x - 1 gives y(0.5)=1.797443y(0.5) = 1.797443, an error of 0.0025490.002549.

    y(0.5)=1.797443∣error∣=0.002549\begin{gathered} y(0.5) = 1.797443 \\ |\text{error}| = 0.002549 \end{gathered}
  7. Result

    The value after 55 steps.

    y(0.5)≈1.794894y(0.5) \approx 1.794894

Worked examples