A solver can return a smooth curve and a tidy table of numbers for a problem nobody meant to pose. Each check in this lesson looks at a different part of the problem, the equation, the data, the interval, the error trend or the units, and none of them replaces the others. Throughout, is the independent variable and . The running example is the dimensionless problem with , whose solution exists for , and the lesson uses it to show what each check can and cannot establish.
Key terms
Equation residual
Definition For a differential equation and a candidate function on an interval, the equation residual is
Here is continuous and differentiable except possibly at finitely many points, and is computed wherever exists. A solution has throughout its interval, and an approximation with residual solves the nearby equation exactly. For output known only at grid points, is an interpolant, so the residual also reflects the interpolation, and differentiating noisy data can magnify errors. A small residual is not by itself a bound on the error. Suppose on , the initial error is , and with on a region containing the graphs of and of the solution . Then the error satisfies
for . The growing factor shows how a sensitive problem can turn a small residual into a large error.
In plain words Put the computed curve back into the equation and see how badly it fails. Zero failure means a solution. A small failure means the curve solves an equation close to the intended one, and how far apart the two solutions drift depends on how sensitive the problem is.
Example For with ,
so the residual is zero. Two Euler steps with give and , and joining the points by straight lines gives a polygon . On the first step , so its residual falls from to at . On the second step the slope is , and the residual reaches at . For both graphs stay in the strip , where , so the bound with , and guarantees an error of at most about at . The actual error is . The bound is valid but loose, and the large residual already warns that the steps are too coarse.
Initial and boundary checks
Definition A solution of an initial-value problem must satisfy the differential equation on an interval containing and also the initial condition . A solution of a boundary-value problem must satisfy every boundary condition. These checks are separate from the residual, because the equation alone has a whole family of solutions, and a zero residual cannot tell which member was intended. For computed output, the same check confirms that the data actually entered are the data stated, including the starting time and the units.
In plain words Passing the equation shows that the curve belongs to the right family. Passing the data shows that it is the right member of that family. A computation needs both.
Example The function has zero residual for on , since , but . It solves the equation and fails the problem with . In fact the zero function and every function solve the equation, and only the initial value picks out . In the same way, take the boundary-value problem on , with as the independent variable and . The function satisfies the equation and the left condition but has the value at , so only the boundary check exposes it.
Event detection
Definition An event is a time at which a chosen scalar event function of the solution is zero, such as the first time a state reaches a threshold. Event detection checks the sign of along the computed solution after each step. When changes sign between and , the solver locates the root inside the step from its interpolant, by bisection or a secant-type method, to a set tolerance. It records the direction of the crossing, increasing when goes from negative to positive, and it may stop the integration there. Reporting the first grid time past the threshold instead gives an event time that can be late by up to one step, and a sign test at grid points alone can miss two crossings that fall inside one step.
In plain words Often the answer wanted is a moment, not a whole curve. The solver watches a quantity, notices when it changes sign during a step, and then zooms in on the crossing instead of rounding to the next grid point.
Example For and the event function , the equation gives , so . There , so crosses zero in the increasing direction. Suppose accurate values are known at and , namely and . The first grid time past the level is , which is late. Linear interpolation between the two points gives , off by . A cubic interpolant that also uses the slopes at both points gives , off by about .
Events versus singularities
Definition An event lies inside the interval of existence, and the solution continues past it. A singularity, in the sense used here, is a finite endpoint of the maximal interval of existence, where the solution becomes unbounded or comes arbitrarily close to the edge of the region on which the equation is defined. No classical solution of the problem continues through it. A third kind of limit is a validity boundary of the model, beyond which the equation may still have a solution but no longer describes the system. A stopping event, a validity boundary and a singularity are different reasons to end a computation, and a report should say which one occurred.
In plain words Reaching a level is something that happens to a solution on its way. A singularity is the end of the road for that solution. A solver that keeps printing numbers past a singularity is not showing a continuation.
Example The solution has maximal interval , and both and tend to as . The event at is an ordinary point of this interval, while is its end. Fixed-step methods do not notice the end. Euler with produces the finite values at and at , so its polygon first passes the level after the singularity. None of the values at or beyond describe the solution. The formula is also defined for , where it is negative, but that branch solves a different problem, such as , and no finite value at joins it to the data at . An adaptive solver usually reveals the singularity by shrinking its steps without limit near and stopping with a warning, which is a signal to analyze the problem, not a failure to hide.
Convergence under refinement
Definition A refinement study repeats a computation with smaller fixed steps, or with tighter tolerances for an adaptive solver, and compares the quantity of interest, such as the state at a fixed time or an event time. For a method of order on a smooth problem, the error at a fixed time behaves like for small , with independent of , so halving the step should divide the error, and the differences between successive runs, by about . The observed ratio approaches only once is small enough, and the difference between the two finest runs, divided by , then estimates the error of the finer one. An independent check compares the result with evidence that could fail in a different way, such as an exact solution of a special case, a conserved quantity, a different method or solver, or a physical limit. Refinement shows that the digits of the computed problem have settled, not that the computed problem is the intended one.
In plain words Run the computation again with smaller steps and see whether the answer stops moving at the rate the method promises. Then test it against something that does not share its assumptions, because a wrong equation converges just as nicely as a right one.
Example Euler’s method for with gives these values at , where the exact value is .
| Step | Euler value | Error |
|---|---|---|
The successive error ratios are , , , and . They approach , as they should for a first-order method, but only slowly, because the derivatives of the solution grow quickly toward the blowup at and keep the higher-order error terms significant. With , the difference between the two finest runs is a fair estimate of the remaining error . Here the exact solution serves as the independent check.
Unit consistency
Definition An equation is unit consistent when all terms that are added, subtracted or equated have the same dimension once their units are converted, and every argument of an exponential, a logarithm or a trigonometric function is dimensionless. A derivative carries the units of divided by those of . Parameters get their units from this requirement, and every numerical value must be entered in one consistent system of units. Error tolerances carry units too. A solver typically accepts a step when the estimated error in each component is at most , so an absolute tolerance has the units of its component and has to be chosen for each component separately.
In plain words Every term of a model has to measure the same kind of quantity in the same units, or the equation adds things that cannot be added. A unit check costs almost nothing and catches mistakes that no amount of refinement can find.
Example Suppose a concentration in obeys with in minutes. The left side has units and has units , so must have units , which is inverse concentration per time. With , the scaled variables and are dimensionless, and
so the model becomes with , the running example with in place of , as in the lesson on units and nondimensionalization. For and , the time scale is . The singularity at is then at , and the event , which is , comes at .
Check yourself
- A program reports as the solution of with . Which checks does it pass, and which does it fail?
Show the answer
It passes the initial check, since . For the residual,
which is never zero and equals at , so it fails the equation. The function fails the other way, with zero residual and the wrong initial value. Only passes both checks.
- For the running example, find the time when reaches and the direction of the crossing. A fixed-step Euler run with reports and and places the crossing of between and . What is wrong with that report?
Show the answer
The equation gives , and there , so the crossing is increasing. The Euler report places the event after , where the solution has already become unbounded. The maximal interval of the problem is , so the values at and belong to no solution of this problem, and the method has simply stepped over the singularity. Euler with this step is also far too coarse, since at it gives only about instead of .
- In the concentration model of the unit card, the rate constant is really , but the program measures in minutes and uses the number . Runs with two very different tolerances agree that reaches at . What does the agreement show, and what is the correct event time?
Show the answer
The agreement shows only that the program solved its own problem accurately. That problem has the wrong rate constant, and refinement cannot detect it. In minutes the constant is , so per minute and the time scale is . The event is still at , which is
The true solution blows up at , so the reported time of lies far beyond its interval of existence. A unit check of catches the mistake at once.