Euler's Method Calculator
Enter dy/dx = f(x, y), an initial point and an end value, and get the approximate solution by Euler's method, the improved Euler (Heun) method or fourth-order Runge–Kutta, with the full step table including every slope, the error against the exact solution (or an accurate reference), what happens as the step is halved, and a graph of the slope field with the solution drawn over it. Free, no sign-up.
Use x for the independent variable and y for the unknown, with + − * / ^ and brackets: x + y, x*y, y*(1 − y), sin(x) − y. Functions: sin, cos, tan, exp, ln, sqrt and more.
If you know the exact solution, enter it in x to see the true error; otherwise a very accurate RK4 reference is used.
Results
3.1874849
Approximation of y(1)
3.4365637
Exact y(1)
-0.249
Error
0.1
Step size h
10
Steps n
The method
yₙ₊₁ = yₙ + h·f(xₙ, yₙ): follow the slope at the start of each step. Global error is proportional to h.
Step table
| n | xₙ | yₙ | k1 | Exact y(xₙ) | Error |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0.1 | 1.1 | 1.2 | 1.1103418 | -0.0103 |
| 2 | 0.2 | 1.22 | 1.42 | 1.2428055 | -0.0228 |
| 3 | 0.3 | 1.362 | 1.662 | 1.3997176 | -0.0377 |
| 4 | 0.4 | 1.5282 | 1.9282 | 1.5836494 | -0.0554 |
| 5 | 0.5 | 1.72102 | 2.22102 | 1.7974425 | -0.0764 |
| 6 | 0.6 | 1.943122 | 2.543122 | 2.0442376 | -0.101 |
| 7 | 0.7 | 2.1974342 | 2.8974342 | 2.3275054 | -0.13 |
| 8 | 0.8 | 2.4871776 | 3.2871776 | 2.6510819 | -0.164 |
| 9 | 0.9 | 2.8158954 | 3.7158954 | 3.0192062 | -0.203 |
| 10 | 1 | 3.1874849 | 3.4365637 | -0.249 |
The three methods with the same step
| Method | y at the end | Error |
|---|---|---|
| Euler's method | 3.1874849 | -0.249 |
| Improved Euler (Heun) | 3.4281617 | -0.0084 |
| Runge–Kutta 4 | 3.4365595 | -0.00000417 |
Halving the step (Euler's method)
| n | h | y at the end | Error |
|---|---|---|---|
| 10 | 0.1 | 3.1874849 | -0.249 |
| 20 | 0.05 | 3.3065954 | -0.13 |
| 40 | 0.025 | 3.3701277 | -0.0664 |
| 80 | 0.0125 | 3.4029699 | -0.0336 |
For Euler's method the error roughly halves when h is halved; for Heun's it falls to a quarter; for RK4 to a sixteenth.
Graph
- Exact solution
- Euler's method
How to Use the Euler's Method Calculator
- 1. Enter the equation. Write the right-hand side of dy/dx = f(x, y) using x and y:
x + y,y*(1 - y),sin(x) - y. - 2. Give the initial condition and the end. Enter x₀, y₀ = y(x₀) and the x-value to solve up to. The end can be to the left of x₀.
- 3. Choose the step. Enter a step size h, or switch to a number of steps n. If h does not divide the interval evenly, the calculator adjusts it and tells you.
- 4. Pick a method and read the table. Each row lists xₙ, yₙ and the slopes used. If you know the exact solution, type it in to see the true error.
The Three Methods
| Method | Step | Global error |
|---|---|---|
| Euler | yₙ₊₁ = yₙ + h·f(xₙ, yₙ) | proportional to h |
| Improved Euler (Heun) | yₙ₊₁ = yₙ + (h/2)(k₁ + k₂), with k₁ = f(xₙ, yₙ) and k₂ = f(xₙ + h, yₙ + h·k₁) | proportional to h² |
| Runge–Kutta 4 | yₙ₊₁ = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄) | proportional to h⁴ |
Euler's method follows the tangent line at the start of each step. Heun's method averages the slope at the start with the slope at the predicted end, which is why it is also called the explicit trapezoid rule. Runge–Kutta 4 samples the slope four times per step and weights them 1, 2, 2, 1. These are the methods of Burden and Faires, Numerical Analysis, chapter 5.
Worked Example: y′ = x + y, y(0) = 1
The exact solution is y = 2eˣ − x − 1, so y(1) = 2e − 2 ≈ 3.4365637. With Euler's method and h = 0.1 the first steps are:
| n | xₙ | yₙ | slope f(xₙ, yₙ) | exact y(xₙ) |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 1 |
| 1 | 0.1 | 1.1 | 1.2 | 1.1103418 |
| 2 | 0.2 | 1.22 | 1.42 | 1.2428055 |
| 3 | 0.3 | 1.362 | 1.662 | 1.3997176 |
For example, y₁ = 1 + 0.1 × (0 + 1) = 1.1 and y₂ = 1.1 + 0.1 × (0.1 + 1.1) = 1.22. After ten steps Euler's method reaches y(1) ≈ 3.1874849, an error of −0.2491: it underestimates because the true solution is convex and the tangent lines lie below it.
| Steps n (h) | Euler error at x = 1 | Heun error | RK4 error |
|---|---|---|---|
| 10 (0.1) | −0.2491 | −0.0084 | −0.0000042 |
| 20 (0.05) | −0.1300 | −0.0022 | −0.00000027 |
| 40 (0.025) | −0.0664 | −0.00056 | −0.000000017 |
| 80 (0.0125) | −0.0336 | −0.00014 | −0.0000000011 |
Each halving of h cuts Euler's error about in half, Heun's to a quarter and RK4's to a sixteenth, as the table of orders predicts. To match RK4's error at n = 10, Euler's method would need several hundred thousand steps.
Reading the Slope Field and the Error
The short segments on the graph show the slope f(x, y) at a grid of points: the true solution is a curve that is tangent to the segments everywhere. The numerical solution is drawn as a polyline over it; if you supply the exact solution it is drawn dashed beside it. Without an exact solution the error column compares with a reference value from RK4 using at least 2,000 steps, which is far more accurate than any method you choose here. Some equations blow up in finite time, like y′ = y² from y(0) = 1 at x = 1; the table stops where the values become infinite.
Frequently Asked Questions
- How does Euler's method work?
- It builds the solution step by step. From the point (xₙ, yₙ) it computes the slope f(xₙ, yₙ) from the differential equation and moves along that tangent line for a horizontal distance h, giving yₙ₊₁ = yₙ + h·f(xₙ, yₙ). Each new point is the starting point for the next step.
- How accurate is Euler's method?
- Its local error per step is proportional to h², but the errors accumulate over about 1/h steps, so the global error is proportional to h. Halving the step halves the error. It is a good method for learning and a poor one for precision.
- What is the improved Euler method?
- The improved Euler method, or Heun's method, first takes an Euler step to predict the end of the interval, then averages the slope there with the slope at the start. That second-order correction makes the global error proportional to h² instead of h, at the cost of two slope evaluations per step.
- How do I choose the step size?
- Use the halving table: reduce h until the answer stops changing in the digits you care about. Euler's method needs a small h, but RK4 reaches the same accuracy with a much larger one. Stiff equations (those with rapidly decaying components) may force a small h on any of these methods.
- Can it solve second-order or systems of equations?
- No. It solves a single first-order equation dy/dx = f(x, y). A second-order equation can be rewritten as a first-order system, but this tool does not handle systems.
- Why does the solution stop partway?
- The values became infinite, which happens when the true solution blows up in finite time or when the step is too large for an unstable equation. The table ends at the last finite row, and the message gives the x-value near which it happened.