# Utility Packages for Numerical Differential Equation Solving

## InterpolatingFunctionAnatomy

NDSolve returns solutions as InterpolatingFunction objects. Most of the time, simply using these as functions does what is needed, but occasionally it is useful to access the data inside, which includes the actual values and points NDSolve computed when taking steps. The exact structure of an InterpolatingFunction object is arranged to make the data storage efficient and evaluation at a given point fast. This structure may change between Wolfram Language versions, so code that is written in terms of accessing parts of InterpolatingFunction objects may not work with new versions of the Wolfram Language. The DifferentialEquations`InterpolatingFunctionAnatomy` package provides an interface to the data in an InterpolatingFunction object that will be maintained for future Wolfram Language versions.

 InterpolatingFunctionDomain[ifun] return a list with the domain of definition for each of the dimensions of the InterpolatingFunction object ifun InterpolatingFunctionCoordinates[ifun] return a list with the coordinates at which data is specified in each of the dimensions for the InterpolatingFunction object ifun InterpolatingFunctionGrid[ifun] return the grid of points at which data is specified for the InterpolatingFunction object ifun InterpolatingFunctionValuesOnGrid[ifun] return the values that would be returned by evaluating the InterpolatingFunction object ifun at each of its grid points InterpolatingFunctionInterpolationOrder[ifun] return the interpolation order used for each of the dimensions for the InterpolatingFunction object ifun InterpolatingFunctionDerivativeOrder[ifun] return the order of the derivative of the base function for which values are specified when evaluating the InterpolatingFunction object ifun

Anatomy of InterpolatingFunction objects.

 In:= One common situation where the InterpolatingFunctionAnatomy package is useful is when NDSolve cannot compute a solution over the full range of values that you specified, and you want to plot all of the solution that was computed to try to understand better what might have gone wrong.

Here is an example of a differential equation which cannot be computed up to the specified endpoint:
 In:=  Out= This gets the domain:
 In:= Out= Once the domain has been returned in a list, it is easy to use Part to get the desired endpoints and make the plot:
 In:= Out= From the plot, it is quite apparent that a singularity has formed and it will not be possible to integrate the system any further.

Sometimes it is useful to see where NDSolve took steps. Getting the coordinates is useful for doing this.

This shows the values that NDSolve computed at each step it took. It is quite apparent from this that nearly all of the steps were used to try to resolve the singularity:
 In:= Out= The package is particularly useful for analyzing the computed solutions of PDEs.

With this initial condition, Burgers' equation forms a steep front:
 In:=   Out= This shows the number of points used in each dimension:
 In:= Out= This shows the interpolation order used in each dimension:
 In:= Out= This shows that the inability to resolve the front has manifested itself as numerical instability:
 In:= Out= This shows the values computed at the spatial grid points at the endpoint of the temporal integration:
 In:= Out= It is easily seen from the point plot that the front has not been resolved.

This makes a 3D plot showing the time evolution for each of the spatial grid points. The initial condition is shown in red:
 In:= Out= When a derivative of an InterpolatingFunction object is taken, a new InterpolatingFunction object is returned that gives the requested derivative when evaluated at a point. The InterpolatingFunctionDerivativeOrder is a way of determining what derivative will be evaluated.

The derivative returns a new InterpolatingFunction object:
 In:= Out= This shows what derivative will be evaluated:
 In:= Out= ## NDSolveUtilities

A number of utility routines have been written to facilitate the investigation and comparison of various NDSolve methods. These functions have been collected in the package DifferentialEquations`NDSolveUtilities`.

 CompareMethods[sys,refsol,methods,opts] return statistics for various methods applied to the system sys FinalSolutions[sys,sols] return the solution values at the end of the numerical integration for various solutions sols corresponding to the system sys InvariantErrorPlot[invts,dvars,ivar,sol,opts] return a plot of the error in the invariants invts for the solution sol RungeKuttaLinearStabilityFunction[amat,bvec,var] return the linear stability function for the Runge–Kutta method with coefficient matrix amat and weight vector bvec using the variable var StepDataPlot[sols,opts] return plots of the step sizes taken for the solutions sols on a logarithmic scale

Functions provided in the NDSolveUtilities package.

 In:= A useful means of analyzing RungeKutta methods is to study how they behave when applied to a scalar linear test problem (see the package FunctionApproximations.m).

This assigns the (exact or infinitely precise) coefficients for the 2-stage implicit RungeKutta Gauss method of order 4:
 In:= Out= This computes the linear stability function, which corresponds to the (2,2) Padé approximation to the exponential at the origin:
 In:= Out= Examples of the functions CompareMethods, FinalSolutions, RungeKuttaLinearStabilityFunction, and StepDataPlot can be found within "ExplicitRungeKutta Method for NDSolve".

Examples of the function InvariantErrorPlot can be found within "Projection Method for NDSolve".

### InvariantErrorPlot Options

The function InvariantErrorPlot has a number of options that can be used to control the form of the result.

 option name default value InvariantDimensions Automatic specify the dimensions of the invariants InvariantErrorFunction Abs[Subtract[#1,#2]]& specify the function to use for comparing errors InvariantErrorSampleRate Automatic specify how often errors are sampled

Options of the function InvariantErrorPlot.

The default value for InvariantDimensions is to determine the dimensions from the structure of the input, Dimensions[invts].

The default value for InvariantErrorFunction is a function to compute the absolute error.

The default value for InvariantErrorSampleRate is to sample all points if there are less than 1000 steps taken. Above this threshold a logarithmic sample rate is used.