Differential Equation Calculator · Linear Initial Value

Model an entered rate and forcing schedule, keep each step inside its segment, and see how halving the numerical step changes error and amplification.

Initial-value equations

Compare solutions of a linear differential equation

Initial value and schedule

For y′ = a y + b, enter the end time, a and b per row. The first segment starts at zero.

Base grid · 8 steps

Solution and error plots

Analytic, Euler and Heun trajectoriesBase grid from zero to 4. The selected station is t = 4. Dashed vertical lines mark changes in the authored coefficients.−0.1212.12024Solution valueTime t
  • Analytic
  • Euler
  • Heun
  • Vertical dashes mark changes
t = 4
Analytic
0.265713
Euler
0.125
Heun
0.286102

Analytic endpoint

0.265713

At t = 4

Euler endpoint

0.125

Final error 0.140713

Largest sampled error 0.735759

Heun endpoint

0.286102

Final error 0.020389

Largest sampled error 0.264241

Segment gains and CSV

Segment 1 · t = 0 to 2

a = -2, b = 4, h = 1/2

Analytic y moves from 0 to 1.963369.

Euler gain
0 · damping
Heun gain
1/2 · damping

Segment 2 · t = 2 to 4

a = -1, b = 0, h = 1/2

Analytic y moves from 1.963369 to 0.265713.

Euler gain
1/2 · damping
Heun gain
5/8 · damping

How to use this calculator

  1. Enter y(0), the maximum base step and one row for each constant-rate interval. Put the end time, a and b on each row.
  2. Compare the analytic curve with Euler and Heun. Switch to half steps to double each segment's step count while retaining its exact boundary.
  3. Open the error graph to see shrinking or growing discrepancy. Inspect an individual time station or jump to the last station.
  4. Read the signed per-step gains and analytic boundary values in the segment ledger. Download both meshes and their errors.

The Formula

The mathematical logic powering this calculation is:

Within a segment the model is y′ = a y + b. When a is zero, y(t₀+s) = y(t₀) + bs. Otherwise use equilibrium e = −b/a and y(t₀+s) = e + [y(t₀) − e] exp(as). Carry the segment-end expression forward to preserve continuity. The analytic path retains sums of exponentials with rational coefficients and exponents before evaluating values in binary64. Equal exponent terms cancel exactly, and nearby terms use expm1 to measure the change.

Divide each segment into N = ceil(duration/h_max) equal steps. Its refined grid has 2N steps, and both grids end exactly on the supplied segment boundary. For f(y) = a y + b, the Euler step is y + h f(y). Heun averages f(y) with f(y + h f(y)) and uses the current segment's coefficients for both slopes.

Differences between two numerical solutions of the same affine equation are multiplied by 1 + z for Euler and 1 + z + z²/2 for Heun, where z = ah. These gains are calculated exactly from rational a and h. Magnitude below one damps a perturbation, magnitude one preserves it, and magnitude above one amplifies it. Amplification is unlike the underlying model on a segment with a < 0.

Errors are the absolute difference from the evaluated analytic solution at mesh points. The maximum error is the largest sampled error and the endpoint error compares the same final t on both grids. Floating-point arithmetic contributes to the measured discrepancy.

Enter 1–6 comma- or tab-separated rows with increasing end times above zero and at most 10, a within ±50 and b and y(0) within ±1,000,000. The maximum step is 0.000001–10. The base grid supports up to 600 steps. Supported numeric input uses a decimal with up to six places or a fraction with a positive denominator of up to six digits.

Worked Example

If you input:

  • Initial value: y(0) = 0
  • Segment 1: Through t = 2, a = −2, b = 4
  • Segment 2: Through t = 4, a = −1, b = 0
  • Maximum base step: 0.5

Result:

At t = 4 the analytic value is approximately 0.265713. Euler gives 0.125 and Heun gives 0.286102 on the base grid. Half steps reduce the endpoint errors to about 0.06627 and 0.00538.

Frequently Asked Questions

Why do the steps end at each schedule change?

The coefficients change there. Ending a step at the change keeps the old rate and forcing on its own interval and applies the new values to the next interval.

What happens when a is zero?

The segment is a straight line with slope b. In exact arithmetic, Euler and Heun both reproduce it.

Why can half steps still give a larger error?

They can remain outside the numerical stability region. A step gain with magnitude greater than one can amplify errors even when the underlying perturbation decays.

Does the gain classify the size of the forcing?

It describes how a perturbation between two solutions propagates across one step. The forcing b affects the trajectory and its equilibrium, while the gain depends on a and the step.

What do you mean by analytic curve?

The curve evaluates the closed-form linear solution carried across each segment. Values use binary64, and the solver preserves exact coefficients and exponent sums at boundaries before evaluation.

Can I enter a nonconstant coefficient in a row?

Each row has fixed a and b. Use additional intervals to model an authored schedule of changes.

Similar Calculators