# 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.

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.

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.

The package is particularly useful for analyzing the computed solutions of PDEs.

It is easily seen from the point plot that the front has not been resolved.

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.

## 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.

A useful means of analyzing Runge–Kutta methods is to study how they behave when applied to a scalar linear test problem (see the package FunctionApproximations.m).

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.