Advanced maths

First-order ODE solver and interactive slope field

Plot a slope field and forward/backward RK4 initial-value curves for an entered f(x,y), choose an initial point and export the SVG.

Your numbers

Use explicit multiplication, x and y, arithmetic, pi, e, sin, cos, tan, exp, ln/log, sqrt or abs. Angles are radians.
Positive magnitude; the backward run uses a negative signed step. At most 5,000 steps per direction.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Try it, understand it

Explore the result

Follow the same rate equation from different initial points, and retain the numerical stopping conditions with the picture.

Worked example comparison
ExampleOutputWhat to notice
Original linear exampleSlope at the initial condition1The initial slope is one; the exact comparison for this example is 2eˣ−x−1.
Nonpolynomial right sideSlope at the initial condition0The exact comparison 1−cos(x) stays between zero and two.
Logistic exampleSlope at the initial condition0.25Inspect a nonlinear initial-value curve approaching different levels in each direction.
Equilibrium trajectorySlope at the initial condition0The selected zero initial condition remains a horizontal equilibrium under this equation.

Check your understanding

Does a slope segment trace a complete solution?

No. It gives local tangent information at one sampled point.

Is a small fixed h a certified error bound?

No. Accuracy and suitability require additional analysis; the tool does not certify error or detect stiffness.

Behind the numbers

How this calculation works

Compile the entered bounded expression once, sample its local slopes over the finite window and integrate the same initial condition in both directions using classical RK4. Stop each trajectory explicitly when it leaves the visible y-window or meets an undefined/numerically unsafe stage. Choose a point on the graph to change x₀ and y₀, or use their labeled form fields.

THE FORMULAClassical RK4: y(next)=y+h(k₁+2k₂+2k₃+k₄)/6 with four right-side evaluations per step

A worked example

For y′=x+y with y(0)=1, the exact comparison solution is y=2eˣ−x−1. Its initial slope is one. The numerical forward curve rises and eventually leaves a ±5 y-window, while the backward curve can reach x=−5. That exact comparison is specific to this example, not an analytic solution produced for every input.

Good to know

Scalar bounded-expression initial-value problems with x,y only. Fixed-step RK4 and finite slope samples, not adaptive/error-certified integration, stiffness detection or symbolic equation classification. The initial condition must lie inside the selected ±range window. Undefined grid samples are omitted; an undefined stage, state above |y|=10¹⁰ or departure from the visible y-window stops that direction.

Start with a rate and one initial condition

A first-order equation y′=f(x,y) states the rate of change of y at a point in the x,y plane. It does not by itself select one trajectory. The initial condition y(x₀)=y₀ identifies the point that a particular solution must pass through. This page keeps that point visible while drawing numerical approximations in both horizontal directions.

Enter a bounded arithmetic expression with explicit multiplication. Functions such as sin(x)*cos(y), exp(−x²) and x−y are supported in the stated grammar. Trigonometric arguments are radians. The expression is parsed as mathematics rather than executed as browser code; unsupported names and undefined evaluations are not silently converted into a different equation.

A little curiosity

Read a slope field as local tangent information

At each sampled grid point, the right side supplies one slope. A short segment with that slope illustrates how a solution would be tangent there if an appropriate solution passes through that point. Positive values tilt upward to the right, negative values tilt downward, and zero values give horizontal segments.

The field is a finite grid, so it does not display every point or certify what happens between them. If the right side is undefined at a grid point, that segment is omitted and counted. In particular, an omitted segment is not a zero slope. The selected initial point must still have a finite right-side value before the numerical curve can begin.

Choose another point inside the graph to set a different initial condition. The labeled x₀ and y₀ fields provide the same operation through keyboard entry. The equation remains unchanged, but the trajectory can change substantially. The graph uses equal coordinate scales so its slope segments are not distorted by independent horizontal and vertical scaling.

Follow the four stages of a Runge–Kutta step

Classical fourth-order Runge–Kutta starts with k₁=f(x,y). It evaluates k₂ at a midpoint predicted from k₁, then k₃ at another midpoint predicted from k₂, and k₄ at a full-step point predicted from k₃. The update combines those slopes as h(k₁+2k₂+2k₃+k₄)/6. This is a local numerical construction, not a symbolic antiderivative.

The entered h is a positive magnitude. The forward run uses positive steps and the backward run uses negative ones. A final shortened step reaches the horizontal window boundary exactly when the run remains valid that far. Each direction stops independently, so a forward problem does not erase valid backward points. The table retains the computed points and the result states why each run ended.

A little curiosity

Compare the worked equation with its known solution

For y′=x+y and y(0)=1, a suitable exact comparison is y=2eˣ−x−1. Its derivative is 2eˣ−1, which equals x+y after substituting the expression for y. At the initial point its slope is one, matching the first result metric. This comparison provides a concrete way to inspect the numerical construction.

For positive x the exponential term grows quickly. In a plot with both axes restricted to ±5, the forward curve can leave the visible vertical range before reaching the right edge. The solver reports that departure rather than implying that the mathematical solution ends there. The backward approximation can continue toward the left edge because its computed values remain within the selected window.

The polynomial initial-value calculator offers a separate method comparison with Euler, Heun and RK4 for polynomial right sides. Its step-halving output studies a different numerical comparison. This page restores the general-expression slope-field task and selectable initial point, while keeping its own finite-window stopping rule explicit.

Recognize the analytic methods without claiming automatic classification

A separable equation has a right side that can be factored into g(x)h(y), allowing a rearrangement involving dy/h(y) and g(x)dx where the algebra is valid. A first-order linear equation can be written y′+P(x)y=Q(x) and treated with an integrating factor. An exact equation written M dx+N dy=0 involves a potential function and an appropriate cross-partial condition.

These are mathematical checks to perform on the equation, not labels inferred from a handful of plotted slopes. The tool numerically evaluates the supplied right side; it does not prove separability, construct an integrating factor or recover an exact potential. Equilibrium solutions and points where division by a factor is invalid also need care in an analytic rearrangement.

Treat a stopping message as information about this run

An undefined RK4 stage prevents the next point from being calculated. A state safety threshold or departure from the visible y-window also stops a direction. Those events describe the numerical run and drawing limit. They do not, by themselves, prove a true blow-up time, prove nonexistence beyond that point or justify jumping through a singularity.

Reducing h can help examine a smooth, nonstiff problem, but a smaller fixed step is not an error certificate. Stiff equations, rapid changes, poles and poorly conditioned problems can require a different method and additional analysis. This solver does not supply adaptive tolerance control, event location or a proof of uniqueness.

The exported SVG records the sampled field, selected initial point and clipped numerical curves. Keep the equation, h, window and stopping messages with a shared graph. The copied scenario and point table provide that context so a visual illustration is not mistaken for an exact solution valid outside the calculation’s scope.

A few questions, answered

Does this tool produce an exact symbolic solution?

No. It uses fixed-step RK4 for a numerical initial-value approximation and samples a slope field.

Why can only one direction stop?

The forward and backward trajectories encounter different values and window edges. They are calculated and reported independently.

Does leaving the graph mean the actual solution ends?

No. It may only mean the numerical trajectory left the selected vertical window.

Can I change the initial condition on the graph?

Yes. Choose a point inside the plot, or enter the same x₀ and y₀ using the labeled fields.

Are undefined field values treated as zero?

No. Undefined grid slopes are omitted and counted. An undefined initial value or numerical stage is handled explicitly.

Find your calculator

Start typing to explore the library.