Differential Equation Calculator

Approximate a first-order initial-value problem with three numerical methods, a step-by-step table, and a plot of the computed solution.

Enter your values

INITIAL-VALUE PROBLEM

Solve a first-order differential equation

dy/dx =

Enter a slope function

f(x,y)f(x,y)
. The equation is interpreted as
dydx=f(x,y)\frac{dy}{dx}=f(x,y)
; trigonometric functions use radians.

Initial condition
y(0)=1y(0)=1
Integrate from x = 0 to x = 1
Press Ctrl + Enter to solve
Try an example
Your numerical solution will appear here.Enter an initial condition and target x, or load an example, then choose a method.

The solver uses a safe, allowlisted expression parser. It does not execute entered text as code.

Overview

What is a differential equation calculator?

A differential equation relates an unknown function to one or more of its derivatives. This calculator solves a first-order initial-value problem numerically: it advances from a known point (x₀, y₀) using the slope rule dy/dx = f(x, y).

Important terms

Initial-value problem (IVP)
A differential equation together with a known function value, such as y(x₀) = y₀, that selects a solution curve locally.
Step size h
The horizontal distance advanced in one numerical update. Smaller steps often improve an approximation, at the cost of more calculations.
Numerical method
A repeatable rule that estimates the next point of a solution curve from the current point and slope evaluations.
Runge–Kutta method of order 4 (RK4)
A common one-step method that combines four slope estimates in a weighted average. It is generally more accurate per step than Euler's method for smooth solutions, but is still approximate.

When this method is useful

  • Explore a first-order IVP when a closed-form solution is inconvenient.
  • Compare how Euler, Heun, and RK4 approximate the same trajectory.
  • Inspect each computed step and see how changing h affects the endpoint estimate.
Formula

Formula and variables

y′=f(x,y),qquady(x0)=y0y'=f(x,y),qquad y(x_0)=y_0
x
independent variable
y(x)
unknown dependent function
f(x,y)
slope prescribed by the differential equation
(x₀,y₀)
known initial point on the solution
h
positive maximum step size; the final step may be shorter

The solver parses f(x,y), then evaluates it at successive numerical points. Euler uses one slope, Heun averages a starting and predicted ending slope, and RK4 combines four slopes. The final interval is shortened when necessary so the calculation lands on the requested target x.

Domain note: This tool computes a numerical approximation for a scalar, first-order explicit equation y′ = f(x,y). It does not find symbolic general solutions, solve implicit or higher-order equations, or prove uniqueness. Inputs must be supported expressions in x and y; trigonometric functions use radians. A numerical result can depend on the selected method and step size.

How it works

How to use this calculator

  1. 1

    Enter the right-hand side f(x,y) in dy/dx = f(x,y).

  2. 2

    Set the initial condition y(x₀) = y₀, the target x, and the maximum step size h.

  3. 3

    Choose Euler, Heun, or fourth-order Runge–Kutta (RK4), then solve.

  4. 4

    Read the approximate endpoint, computed point table, plot, and update rule. Repeat with a smaller h to compare sensitivity.

Worked examples

Step-by-step examples

Example 1

Problem: Approximate y(1) for y′ = y with y(0) = 1 using RK4 and h = 0.1.

Substitution: At each step, RK4 combines k₁ = f(xₙ,yₙ), k₂ = f(xₙ+h/2,yₙ+hk₁/2), k₃ = f(xₙ+h/2,yₙ+hk₂/2), and k₄ = f(xₙ+h,yₙ+hk₃).

Result: After 10 steps, y(1) ≈ 2.71828.

The exact solution is y = eˣ, so y(1) = e ≈ 2.71828. The numerical value is an approximation; changing h or the method may change its last digits.

Example 2

Problem: Approximate y(1) for y′ = x + y, y(0) = 1, with RK4 and h = 0.1.

Substitution: Use the RK4 slope evaluations with f(x,y) = x + y at each of 10 steps.

Result: y(1) ≈ 3.43656.

The exact solution is y = 2eˣ − x − 1, giving y(1) = 2e − 2 ≈ 3.43656; this provides a check for the numerical approximation.

Example 3

Problem: Approximate y(1) for y′ = −y, y(0) = 1, with RK4 and h = 0.1.

Substitution: Apply RK4 to f(x,y) = −y for 10 steps.

Result: y(1) ≈ 0.36788.

The exact solution is y = e⁻ˣ, so the endpoint is e⁻¹ ≈ 0.36788.

Method knowledge

Rules, edge cases, and related ideas

Euler: one slope per step

Euler follows the tangent estimate yₙ₊₁ = yₙ + h f(xₙ,yₙ). It is easy to inspect and often useful for learning, but may need small steps for good accuracy.

Heun: predictor and correction

Heun predicts an endpoint with Euler, evaluates the slope there, then averages the starting and predicted slopes. This is also called the improved Euler or explicit trapezoidal method.

RK4: weighted slopes

The classical fourth-order Runge–Kutta step samples the beginning, two midpoints, and end of the interval, then combines those slopes with weights 1, 2, 2, and 1.

Edge cases and limitations

  • A target equal to x₀ returns the initial value without taking a step.
  • A target below x₀ is supported; the solver integrates backward while h remains a positive step-size magnitude.
  • If the interval is not a whole multiple of h, the final step is shortened to end at the target.
  • The solver rejects a non-finite slope or an unsupported expression and reports the step where evaluation failed.
  • At most 500 steps are allowed per calculation. Increase h or shorten the interval if more would be needed.
  • Trigonometric inputs are interpreted in radians, and numerical stability is not guaranteed for every equation or step size.

How this differs from a related concept

An exact symbolic differential-equation solver seeks a formula for a family of solutions. This calculator instead follows one initial condition numerically and reports an approximate trajectory; it is useful for exploration, including equations without a convenient elementary closed form.

Interpretation

Understand the result

The displayed endpoint and table are computed from the selected method and step size. They should not be read as an exact symbolic solution. Compare runs with smaller h, or compare Euler, Heun, and RK4, to see whether the estimate is stable. For equations with singularities or rapidly changing slopes, reduce h and check the function domain across the full interval.

Common mistakes

  • Treating a numerical endpoint as an exact solution. The output is approximate and depends on the chosen step size and method.
  • Confusing the initial value y₀ with the target value y(x). The initial condition starts the integration; the target is where it stops.
  • Using an excessively large step near a sharp change, discontinuity, or singularity. Try a smaller h and inspect where the slope becomes undefined.
  • Entering a second-order equation in the first-order field. A second-order equation must first be rewritten as a system of first-order equations, which this calculator does not do automatically.
  • Assuming RK4 guarantees accuracy for any h. Its accuracy order describes behavior for sufficiently smooth problems as the step size becomes small; it is not an unconditional guarantee.

Frequently asked questions

What differential equations can this calculator solve?

It numerically advances scalar, first-order explicit initial-value problems written as dy/dx = f(x,y), using supported functions of x and y.

Does it give an exact symbolic solution?

No. It returns numerical approximations at discrete steps and at the requested endpoint. It does not derive a general closed-form solution.

Which method should I choose?

RK4 is a good general-purpose choice for smooth problems. Heun is a useful second-order predictor-corrector, and Euler is the simplest method to follow by hand. Compare methods and reduce h to examine sensitivity.

Can I integrate backward from the initial point?

Yes. Enter a target x smaller than x₀. The calculator uses signed steps to integrate backward while treating the entered h as a positive step-size magnitude.

Why do different step sizes give different answers?

Each method approximates a continuous curve using finite steps. Truncation error accumulates; smaller steps often reduce it for smooth, well-behaved problems, although no method is guaranteed to work well for every equation.

What does the plot show?

It connects the initial value and the numerical points actually computed by the selected method. The line segments are visual guides, not a separately solved exact curve.

References & technical sources

Keep calculating

Related calculators