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 which is written in terms of accessing parts of
InterpolatingFunction objects may not work with new versions of
Mathematica. The
DifferentialEquations`InterpolatingFunctionAnatomy` package provides an interface to the data in an
InterpolatingFunction object which 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 which 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 which was computed to try to understand better when might have gone wrong.
Here is an example of a differential equation which cannot be computed up to the specified endpoint.
| Out[2]= |  |
|
| Out[3]= |  |
|
Once the domain has been returned in a list, it is easy to use Part to get the desired endpoints and make the plot.
| 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.
This shows the values which 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.
| Out[7]= |  |
|
The package is particularly useful for analyzing the computed solutions of PDEs
With this initial condition, Burgers' equation forms a steep front.
| Out[8]= |  |
|
This shows the number of points used in each dimension.
| Out[9]= |  |
|
This shows the interpolation order used in each dimension.
| Out[10]= |  |
|
This shows that the inability to resolve the front has manifested itself as numerical instability.
| Out[11]= |  |
|
This shows the values computed at the spatial grid points at the endpoint of the temporal integration.
| Out[14]= |  |
|
It is easily seen from the point plot that the front has not been resolved.
This makes a 3D plot showing how the time evolution for each of the spatial grid points. The initial condition is shown in red.
| Out[15]= |  |
|
When a derivative is taken of an
InterpolatingFunction object, a new
InterpolatingFunction object is returned which gives the requested derivative when evaluated at a point. The
InterpolatingFunctionDerivativeOrder is a way of determining what derivative will be evaluated.
| Out[16]= |  |
|
This shows what derivative will be evaluated.
| 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
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, weight vector bvec using the variable var |
| StepDataPlot[sols,opts] | return plots of the step sizes taken for the solutions sols |
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).
This assigns the (exact or infinitely precise) coefficients for the 2-stage implicit Runge-Kutta Gauss method of order 4.
| Out[19]= |  |
|
This computes the linear stability function, which corresponds to the (2,2) Padé approximation to the exponential at the origin.
| Out[20]= |  |
|
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.
| | |
| 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.