Euler’s Method Calculator
Numerical solution of y′ = f(x, y)Approximate the solution of a first-order ODE \(y' = f(x, y)\) with an initial condition \(y(x_0) = y_0\) using Euler’s method and improved Euler (Heun). Get a full step table, optional exact solution comparison, error metrics and a simple plot.
Perfect for students, instructors and engineers who need a transparent, step-by-step implementation of Euler’s method – not a black box.
1. Define the differential equation and parameters
Use x and y, operators +, -, *, /, ^ and functions like sin(x), cos(x), exp(x), log(x).
Smaller h ⇒ more steps, higher accuracy, more work.
Final point: xN = x₀ + N·h.
“Both” computes two trajectories on the same grid.
If provided, the calculator evaluates y(x) at each grid point to estimate numerical error.
2. Summary of the numerical solution
3. Plot of numerical solution (and exact, if provided)
The plot shows the approximate solution on the grid points. If an exact solution is given, it is overlayed as a smooth curve for visual comparison.
4. Step-by-step table
Each row corresponds to one grid point xn. For “Both” mode you get Euler and Heun values side by side. If the exact solution is known, absolute errors are shown as well.
| n | xₙ | yₙ (Euler) | yₙ (Heun) | y(xₙ) exact | |error| (Euler) | |error| (Heun) |
|---|
Mathematical definition of Euler’s method
Consider the initial value problem (IVP) \[ y' = f(x,y), \quad y(x_0) = y_0. \] Choose a step size \(h > 0\) and define the grid \(x_n = x_0 + n h\) for \(n = 0, 1, \dots, N\). Euler’s method constructs approximate values \(y_n \approx y(x_n)\) via
\[ y_{n+1} = y_n + h\, f(x_n, y_n), \quad n = 0,1,\dots,N-1. \]
Geometrically, each step moves along the tangent line at \((x_n, y_n)\) with slope \(f(x_n, y_n)\). This gives a piecewise linear approximation of the true solution.
Improved Euler (Heun) method
The improved Euler method, also known as Heun’s method, reduces the error by averaging slopes:
Predictor: \[ \tilde{y}_{n+1} = y_n + h\, f(x_n, y_n), \] Corrector: \[ y_{n+1} = y_n + \frac{h}{2}\Big(f(x_n, y_n) + f(x_{n+1}, \tilde{y}_{n+1})\Big). \]
This is a simple second-order Runge–Kutta method. For the same step size h, Heun’s method usually gives a much more accurate approximation than standard Euler.
Error behaviour and step size
For sufficiently smooth solutions, the local truncation error of Euler’s method is \(O(h^2)\) while the global error is \(O(h)\). This means that, roughly, halving the step size halves the global error. Improved Euler has global error \(O(h^2)\), so the error decreases much faster when h is reduced.
In practice, you can:
- Compute with step size h.
- Repeat with step size h/2.
- Compare the two approximations to estimate the error and choose a suitable h.
When to use Euler’s method
- Teaching and learning: Euler’s method is often the first numerical scheme introduced in differential equations courses because the idea is easy to visualize and implement.
- Quick prototyping: For simple non-stiff problems on short intervals, Euler’s method can provide a quick “sanity check” before using more advanced solvers.
- Derivation of higher-order methods: Many Runge–Kutta methods can be understood as refined versions of Euler’s idea of following slopes along the solution curve.
FAQ: using this Euler’s method calculator
Which expressions are allowed for f(x, y) and y(x)?
You can use arithmetic operators +, -, *, /, ^ and standard JavaScript math functions such as sin, cos, tan, exp, log, sqrt. For example: y - x^2, x * y, exp(x) - y.
What if the method “blows up” or behaves strangely?
Large step sizes can make explicit Euler unstable, especially for stiff or rapidly changing solutions. Try reducing h or switching to improved Euler. If the problem is stiff, specialised implicit methods or dedicated ODE solvers are recommended.
Can I export the table data?
You can easily copy the table from the browser into a spreadsheet or document. The clean numeric format is designed to paste well into tools like Excel, Google Sheets or LaTeX tables.