Direction Field Visualizer
Plot slope fields and trace solution curves for \(y' = f(t,y)\) with an adaptive Tsit5 solver and automatic stiffness switching to BDF5 — click anywhere on the field to draw a solution curve through that point.
What Is a Direction Field?
A direction field (or slope field) for \(y' = f(t,y)\) places a short arrow at each grid point \((t,y)\) whose slope equals \(f(t,y)\). Any solution curve must be tangent to the arrows everywhere it passes.
Adaptive Solver — Two Trajectory Modes
Clicking a point \((t_0,y_0)\) solves the IVP with an adaptive Tsitouras 5(4) (Tsit5) explicit Runge–Kutta method with FSAL (the final stage of an accepted step is reused as the first stage of the next, giving an effective cost of six derivative evaluations). Step size is automatically shrunk near steep slopes and enlarged in smooth regions.
The Trajectory Mode selector chooses how the curve is parameterised:
- t-step (default) — integrates \(y(t)\) directly from \(y' = f(t,y)\). Fastest and most familiar; one \(y\) value per \(t\). Stops short of vertical tangents and pole-style singularities (e.g. \(y' = -t/y\) at \(y = 0\)).
- Arc-length — integrates the equivalent autonomous 2D system \(\dot{t} = \cos\theta,\ \dot{y} = \sin\theta\) where \(\theta = \arctan f(t,y)\). The unit-speed RHS stays bounded as \(f \to \pm\infty\), so vertical tangents are crossed smoothly and full implicit curves close up — \(y' = -t/y\) traces complete circles in one click. This is exactly the trick used by phase portraits to draw trajectories of \(\dot{x} = Q(x,y),\ \dot{y} = P(x,y)\).
Solver Method — Non-stiff vs. Stiff
The Solver Method selector chooses the time integrator for the t-step mode:
- Auto (default) — starts with explicit Tsit5 and watches a stiffness indicator \(|h\,\hat L|\), where \(\hat L \approx |\partial f/\partial y|\) is estimated for free from the FSAL stages (the Tsit5 linear-stability boundary on the negative real axis is \(\approx 3.3\)). When the indicator stays elevated for many steps — the signature of a step held down by stability rather than accuracy — the run is declared stiff and continued with BDF5. Smooth non-stiff equations (even steep or blow-up cases) stay on Tsit5.
- Tsit5 (non-stiff) — the adaptive explicit Runge–Kutta method above; best for smooth, non-stiff equations.
- BDF5 (stiff) — a 5th-order backward differentiation formula, an implicit linear multistep method solved at each step by Newton's method (first five points bootstrapped with Tsit5). Being A(\(\alpha\))-stable, it integrates stiff equations such as \(y' = -50\,(y - \cos t)\) without the tiny steps an explicit method would require.
- DOP853 (8(5,3)) — dense — the order-8 Dormand–Prince method with its embedded 5th/3rd-order error pair for step control and a 7th-order continuous (dense) output. The large error-controlled steps are interpolated by the dense polynomial, so the plotted curve stays smooth while following the true solution to high precision — ideal for accurate non-stiff trajectories with far fewer accepted steps.
BDF5: \(\;\tfrac{137}{60}y_{n+1} - 5y_n + 5y_{n-1} - \tfrac{10}{3}y_{n-2} + \tfrac{5}{4}y_{n-3} - \tfrac{1}{5}y_{n-4} = h\,f(t_{n+1},y_{n+1})\)
(Arc-length mode always uses Tsit5: its unit-speed right-hand side is bounded and non-stiff by construction.)
How to Use
- Type \(f(t,y)\) in the equation box. Use
torxfor the independent variable. - Press Enter or click Update Field to redraw the arrows.
- Click anywhere on the canvas to trace a solution curve through that point, or type an exact \((t_0, y_0)\) in the Initial condition box and press Add curve (keyboard-friendly).
- Multiple curves use distinct colors automatically.
- Clear Solutions removes all curves. Download PNG saves the view.
Keyboard Navigation
- Tab through all controls; Enter in the equation field updates the plot.
- Click function names in the table to insert them directly into the equation box.
Direction field visualization. Click on the canvas to draw a solution curve through the chosen point.
Each example loads in arc-length mode so vertical tangents are crossed and full implicit curves close up. Bounds use a 5:3 aspect ratio matching the canvas, so circles look round. Click anywhere on the field after loading.
Click a function name to insert it into the equation box.
| Code | Notation |
|---|---|
| sqrt(x) | \(\sqrt{x}\) |
| cbrt(x) | \(\sqrt[3]{x}\) |
| abs(x) | \(|x|\) |
| sin(x) | \(\sin x\) |
| cos(x) | \(\cos x\) |
| tan(x) | \(\tan x\) |
| cot(x) | \(\cot x\) |
| sec(x) | \(\sec x\) |
| csc(x) | \(\csc x\) |
| asin(x) | \(\arcsin x\) |
| acos(x) | \(\arccos x\) |
| atan(x) | \(\arctan x\) |
| sinh(x) | \(\sinh x\) |
| cosh(x) | \(\cosh x\) |
| tanh(x) | \(\tanh x\) |
| exp(x) | \(e^{x}\) |
| log(x) | \(\ln x\) |
| log10(x) | \(\log_{10} x\) |
| pi | \(\pi\) |
| e | \(e\) |
| ceil(x) | \(\lceil x\rceil\) |
| floor(x) | \(\lfloor x\rfloor\) |
| round(x) | \(\operatorname{round}(x)\) |
| max(a,b) | \(\max(a,b)\) |
| min(a,b) | \(\min(a,b)\) |
Cite this tool
Kapita, S. (2026). Direction Field Visualizer. Math Tools. https://doi.org/10.5281/zenodo.20981380
Kapita, Shelvean. "Direction Field Visualizer." Math Tools, 2026, doi.org/10.5281/zenodo.20981380.
@online{kapita2026slope,
author = {Shelvean Kapita},
title = {{Direction Field Visualizer}},
year = {2026},
organization = {Math Tools},
doi = {10.5281/zenodo.20981380},
url = {https://doi.org/10.5281/zenodo.20981380}
}