# 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 *Mathematica* versions, so code that is written in terms of accessing parts of InterpolatingFunction objects may not work with new versions of *Mathematica*. The package provides an interface to the data in an InterpolatingFunction object that will be maintained for future *Mathematica* 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[1]:= |

One common situation where the 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.

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

In[4]:= |

Out[5]= |

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.

In[6]:= |

Out[7]= |

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

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

In[12]:= |

Out[14]= |

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

In[15]:= |

Out[15]= |

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 is a way of determining what derivative will be evaluated.

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

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

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

In[18]:= |

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

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

Examples of the functions , , , and can be found within "ExplicitRungeKutta Method for NDSolve".

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

### InvariantErrorPlot Options

The function 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 |

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

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

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