Advanced maths

Scalar ODE terminal-state parameter sensitivity calculator with an adjoint gradient

A parameter sensitivity asks how a model output changes when a constant parameter changes slightly.

Your numbers

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

Behind the numbers

How this calculation works

A parameter sensitivity asks how a model output changes when a constant parameter changes slightly. Here the output is specifically the scalar terminal state y at time T. The state starts from a fixed supplied initial value, and the parameter z appears inside a smooth scalar differential equation.

THE FORMULAy′=f(t,y,z);λ′=−f_y λ,λ(T)=1;d y(T)/dz=integral λ f_z dt.

A worked example

For y′=0.7y,y(0)=1,T=2,the exact terminal state is exp(1.4)≈4.055199967 and parameter gradient2exp(1.4)≈8.110399934.

Good to know

Scalar smooth state equation,one constant parameter z,fixed initial state,objective y(T),T≤20,40–1,000 coarse steps;RK4 doubled mesh,finite-difference partials and gradient comparison. No nonsmooth events or arbitrary objectives.

Differentiate a terminal state with respect to one parameter

A parameter sensitivity asks how a model output changes when a constant parameter changes slightly. Here the output is specifically the scalar terminal state y at time T. The state starts from a fixed supplied initial value, and the parameter z appears inside a smooth scalar differential equation.

The calculation returns an adjoint gradient with respect to z, the terminal state, the initial adjoint and a finite-difference comparison. It does not support an arbitrary objective function, multiple state variables or a vector of parameters. Those restrictions make the displayed gradient’s meaning explicit and independently checkable.

Scalar terminal-state adjoint sensitivityy(T) = exp(1.4)dy(T)/dz = 2exp(1.4)Forward state;backward λ
Scroll across to see the full diagram.
For y′=0.7y,y(0)=1,T=2,the exact terminal state is exp(1.4)≈4.055199967 and parameter gradient2exp(1.4)≈8.110399934.

Compare this with the First-order ODE solver and interactive slope field. Compute gradients of a terminal objective with respect to model parameters,not only a solution trajectory.

Write the scalar model with named variables

The expression uses t for time, y for state and z for the single constant parameter. Arithmetic, smooth powers and supported smooth functions can be used when their values remain defined over the trajectory. The initial state is treated as independent of the parameter for the parameter-gradient calculation.

A separate initial adjoint measures sensitivity of the terminal state to its initial value. If your actual initial condition depends on z, the total parameter derivative would need an additional chain-rule contribution. The calculator does not infer that dependency from a numerical initial value or add an unstated initial-condition model.

Integrate forward before integrating backward

The state trajectory is first computed forward using a fixed-step fourth-order Runge–Kutta method. The adjoint equation then travels backward from terminal value one, because the objective is the terminal state itself. During that backward pass, stored forward states are interpolated to evaluate the needed model derivatives.

The parameter gradient accumulates the integral of the adjoint multiplied by the derivative of the model with respect to z. The state derivative and parameter derivative are evaluated by central numerical differences. This implementation illustrates the continuous adjoint construction; it is not an automatic differentiation library or a full adaptive sensitivity solver.

Use the exponential example as an analytic check

For y prime equals zy, initial value one, parameter 0.7 and terminal time two, the exact terminal state is exp of 1.4, approximately 4.055200. Differentiating that expression with respect to z gives two times exp of 1.4, approximately 8.110400.

The prefilled calculation approaches those values, with the small remaining discrepancy reflected by its refinement and finite-difference diagnostics. The initial adjoint equals exp of 1.4 in this example. These three linked quantities provide a stronger independent check than merely comparing two numerical parameter derivatives produced by the same solver.

Compare two numerical resolutions

The entered step count defines a coarse grid, and the calculation also runs a grid with twice as many steps. It reports the difference between their adjoint gradients. This refinement difference is useful evidence of numerical sensitivity to the mesh, but it is not a rigorous upper bound on the true derivative error.

A separate centered parameter perturbation computes a finite-difference gradient of the finely resolved forward solution. A disagreement beyond the implementation’s tolerance causes an error instead of a completed sensitivity result. Agreement still does not prove the model is scientifically appropriate or that every source of numerical error has been bounded.

Smoothness and trajectory range matter

Adjoint derivatives require local smoothness along the trajectory. Absolute values, discontinuous switches and unsupported singular functions are excluded from this bounded expression interface. A trajectory approaching a logarithm boundary or a pole can make both the forward integration and numerical derivatives unstable even when the expression parses successfully.

The solver rejects nonfinite or excessively large intermediate values. It also has a terminal-time and step-count budget suitable for small examples rather than stiff or long-horizon models. Increase resolution when appropriate, but do not assume that adding steps repairs an equation with a finite-time singularity or an undefined derivative.

Keep the derivative local and conditional

The gradient describes a local change around the entered parameter while holding the initial value, time horizon and model structure fixed. A large finite parameter change can produce a nonlinear response that is poorly approximated by multiplying this gradient by that change. Recompute or examine a parameter sweep for such questions.

This page supplies no parameter uncertainty propagation, event-time sensitivity or integral running cost. Preserve the exact expression, parameter, initial value, terminal time and step count with the result. Those conditions determine which derivative was computed and make a later independent comparison meaningful.

A few questions, answered

What objective is differentiated?

The scalar terminal state y(T),with fixed initial condition and terminal time.

Can the initial value depend on z?

Not in this interface. The initial state is held fixed;parameter-dependent initial conditions need an additional sensitivity term.

Are the derivatives symbolic?

No. Smooth partial derivatives use centered differences and the adjoint result is compared with a separate parameter finite difference.

What is the refinement value?

The difference between two numerical gradient estimates;it is a diagnostic,not a certified error bound.

Find your calculator

Start typing to explore the library.