Skip to content

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

nxₙyₙk1Exact y(xₙ)Error
001110
10.11.11.21.1103418-0.0103
20.21.221.421.2428055-0.0228
30.31.3621.6621.3997176-0.0377
40.41.52821.92821.5836494-0.0554
50.51.721022.221021.7974425-0.0764
60.61.9431222.5431222.0442376-0.101
70.72.19743422.89743422.3275054-0.13
80.82.48717763.28717762.6510819-0.164
90.92.81589543.71589543.0192062-0.203
1013.18748493.4365637-0.249

The three methods with the same step

Methody at the endError
Euler's method3.1874849-0.249
Improved Euler (Heun)3.4281617-0.0084
Runge–Kutta 43.4365595-0.00000417

Halving the step (Euler's method)

nhy at the endError
100.13.1874849-0.249
200.053.3065954-0.13
400.0253.3701277-0.0664
800.01253.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
Slope field of dy/dx = f(x, y) with the Euler's method solution from x = 0 to x = 100.20.40.60.81123xy

How to Use the Euler's Method Calculator

  1. 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. 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. 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. 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

MethodStepGlobal error
Euleryₙ₊₁ = 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 4yₙ₊₁ = 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:

nxₙyₙslope f(xₙ, yₙ)exact y(xₙ)
00111
10.11.11.21.1103418
20.21.221.421.2428055
30.31.3621.6621.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 = 1Heun errorRK4 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.

Related Tools

More in Math Calculators

See all Math Calculators