"Extrapolation" Method for NDSolve

Introduction

Extrapolation methods are a class of arbitrary-order methods with automatic order and step-size control. The error estimate comes from computing a solution over an interval using the same method with a varying number of steps and using extrapolation on the polynomial that fits through the computed solutions, giving a composite higher-order method [BS64]. At the same time, the polynomials give a means of error estimation.

Typically, for low precision, the extrapolation methods have not been competitive with Runge–Kutta-type methods. For high precision, however, the arbitrary order means that they can be arbitrarily faster than fixed-order methods for very precise tolerances.

The order and step-size control are based on the codes odex.f and seulex.f described in [HNW93] and [HW96].

This loads packages that contain some utility functions for plotting step sequences and some predefined problems:

Needs["DifferentialEquations`NDSolveProblems`"];
Needs["DifferentialEquations`NDSolveUtilities`"];

"Extrapolation"

The method "DoubleStep" performs a single application of Richardson's extrapolation for any one-step integration method and is described within "DoubleStep Method for NDSolve".

"Extrapolation" generalizes the idea of Richardson's extrapolation to a sequence of refinements.

Consider a differential system

y'(t)==f(t,y(t)),y((Subscript[t, 0]))==(Subscript[y, 0]).

Let H>0 be a basic step size; choose a monotonically increasing sequence of positive integers

and define the corresponding step sizes

by

Choose a numerical method of order p and compute the solution of the initial value problem by carrying out (Subscript[n, i]) steps with step size (Subscript[h, i]) to obtain

Extrapolation is performed using the Aitken–Neville algorithm by building up a table of values,

(Subscript[T, i,j])==(Subscript[T, i,j-1])+(((Subscript[T, i,j-1])-(Subscript[T, i-1,j-1]))/((((((Subscript[n, i])/(Subscript[n, i-j+1]))))^w)-1)),i==2,…,k,j==2,…,i,

where w is either 1 or 2 depending on whether the base method is symmetric under extrapolation.

A dependency graph of the values in () illustrates the relationship.

Considering k==2, (Subscript[n, 1])==1, (Subscript[n, 2])==2 is equivalent to Richardson's extrapolation.

For non-stiff problems the order of (Subscript[T, k,k]) in () is p + (k-1) w. For stiff problems the analysis is more complicated and involves the investigation of perturbation terms that arise in singular perturbation problems [HNW93, HW96].

Extrapolation Sequences

Any extrapolation sequence can be specified in the implementation. Some common choices are as follows.

This is the Romberg sequence:

NDSolve`RombergSequenceFunction[1, 10]

This is the Bulirsch sequence:

NDSolve`BulirschSequenceFunction[1, 10]

This is the harmonic sequence:

NDSolve`HarmonicSequenceFunction[1, 10]

A sequence that satisfies ((((Subscript[n, i])/(Subscript[n, i-j+1])))^w)≥2 has the effect of minimizing the roundoff errors for an order-p base integration method.

For a base method of order two, the first entries in the sequence are given by the following:

NDSolve`OptimalRoundingSequenceFunction[1, 10, 2]

Here is an example of adding a function to define the harmonic sequence where the method order is an optional pattern:

Default[myseqfun, 3] = 1;

myseqfun[n1_, n2_, p_.]:= Range[n1, n2]

The sequence with lowest cost is the harmonic sequence, but this is not without problems since rounding errors are not damped.

Rounding Error Accumulation

For high-order extrapolation an important consideration is the accumulation of rounding errors in the Aitken–Neville algorithm ().

As an example consider Exercise 5 of Section II.9 in [HNW93].

Suppose that the entries (Subscript[T, 11]),(Subscript[T, 21]),(Subscript[T, 31]),… are disturbed with rounding errors ϵ,-ϵ,ϵ,… and compute the propagation of these errors into the extrapolation table.

Due to the linearity of the extrapolation process (), suppose that the (Subscript[T, i,j]) are equal to zero and take ϵ==1.

This shows the evolution of the Aitken–Neville algorithm () on the initial data using the harmonic sequence and a symmetric order-two base integration method, w == p == 2.

Hence, for an order-sixteen method approximately two decimal digits are lost due to rounding error accumulation.

This model is somewhat crude because, as you will see in "Rounding Error Reduction", it is more likely that rounding errors are made in (Subscript[T, i+1,1]) than in (Subscript[T, i,1]) for i≥1.

Rounding Error Reduction

It seems worthwhile to look for approaches that can reduce the effect of rounding errors in high-order extrapolation.

Selecting a different step sequence to diminish rounding errors is one approach, although the drawback is that the number of integration steps needed to form the (Subscript[T, i,1]) in the first column of the extrapolation table requires more work.

Some codes, such as STEP, take active measures to reduce the effect of rounding errors for stringent tolerances [SG75].

An alternative strategy, which does not appear to have received a great deal of attention in the context of extrapolation, is to modify the base-integration method in order to reduce the magnitude of the rounding errors in floating-point operations. This approach, based on ideas that dated back to [G51], and used to good effect for the two-body problem in [F96b] (for background see also [K65], [M65a], [M65b], [V79]), is explained next.

Base Methods

The following methods are the most common choices for base integrators in extrapolation.

For efficiency, these have been built into (RefLink[NDSolve, paclet:ref/NDSolve]) and can be called via the (RefLink[Method, paclet:ref/Method]) option as individual methods.

The implementation of these methods has a special interpretation for multiple substeps within "DoubleStep" and "Extrapolation".

The (RefLink[NDSolve, paclet:ref/NDSolve]) framework for one-step methods uses a formulation that returns the increment or update to the solution. This is advantageous for geometric numerical integration where numerical errors are not damped over long time integrations. It also allows the application of efficient correction strategies such as compensated summation. This formulation is also useful in the context of extrapolation.

The methods are now described together with the increment reformulation that is used to reduce rounding error accumulation.

Multiple Euler Steps

Given (Subscript[t, 0]), (Subscript[y, 0]), and H, consider a succession of n == (Subscript[n, k]) integration steps with step size h==H/n carried out using Euler's method:

({{(Subscript[y, 1]), ==, (Subscript[y, 0])+hf((Subscript[t, 0]),(Subscript[y, 0]))}, {(Subscript[y, 2]), ==, (Subscript[y, 1])+hf((Subscript[t, 1]),(Subscript[y, 1]))}, {(Subscript[y, 3]), ==, (Subscript[y, 2])+hf((Subscript[t, 2]),(Subscript[y, 2]))}, {⋮, ⋮, ⋮}, {(Subscript[y, n]), ==, (Subscript[y, n-1])+hf((Subscript[t, n-1]),(Subscript[y, n-1]))}})

where (Subscript[t, i])==(Subscript[t, 0])+ih.

Correspondence with Explicit Runge–Kutta Methods

It is well-known that, for certain base integration schemes, the entries (Subscript[T, i,j]) in the extrapolation table produced from () correspond to explicit Runge–Kutta methods (see Exercise 1, Section II.9 in [HNW93]).

For example, () is equivalent to an n-stage explicit Runge–Kutta method:

({{(Subscript[k, i]), ==, f((Subscript[t, 0])+(Subscript[c, i])H,(Subscript[y, 0])+H(∑_(j=1)^n)(Subscript[a, i,j])(Subscript[k, j])),, i==1,…,n,}, {(Subscript[y, n]), ==, (Subscript[y, 0])+H(∑_(i=1)^n)(Subscript[b, i])(Subscript[k, i]),  }})

where the coefficients are represented by the Butcher table:

({{0,  ,  ,  ,  }, {1/n, 1/n,  ,  ,  }, {⋮, ⋮, ⋱,  ,  }, {(n-1)/n, 1/n, ⋯, 1/n,  }, { , 1/n, ⋯, 1/n, 1/n}})

Reformulation

Let Δ (Subscript[y, n])==(Subscript[y, n+1])-(Subscript[y, n]). Then the integration () can be rewritten to reflect the correspondence with an explicit Runge–Kutta method (, ) as

({{Δ (Subscript[y, 0]), ==, hf((Subscript[t, 0]),(Subscript[y, 0]))}, {Δ (Subscript[y, 1]), ==, hf((Subscript[t, 1]),(Subscript[y, 0])+Δ (Subscript[y, 0]))}, {Δ (Subscript[y, 2]), ==, hf((Subscript[t, 2]),(Subscript[y, 0])+(Δ (Subscript[y, 0])+Δ (Subscript[y, 1])))}, {⋮, ⋮, ⋮}, {Δ (Subscript[y, n-1]), ==, hf((Subscript[t, n-1]),(Subscript[y, 0])+(Δ (Subscript[y, 0])+Δ (Subscript[y, 1])+⋯+(Subscript[Δy, n-2])))}})

where terms in the right-hand side of () are now considered as departures from the same value (Subscript[y, 0]).

The Δ (Subscript[y, i]) in () correspond to the h (Subscript[k, i]) in ().

Let ΣΔ (Subscript[y, n])==(∑_(i=0)^(n-1))Δ (Subscript[y, i]); then the required result can be recovered as

(Subscript[y, n])==(Subscript[y, 0])+ΣΔ(Subscript[y, n]).

Mathematically the formulations () and (, ) are equivalent. For n>1, however, the computations in () have the advantage of accumulating a sum of smaller O(h) quantities, or increments, which reduces rounding error accumulation in finite-precision floating-point arithmetic.

Multiple Explicit Midpoint Steps

Expansions in even powers of h are extremely important for an efficient implementation of Richardson's extrapolation and an elegant proof is given in [S70].

Consider a succession of integration steps n == 2 (Subscript[n, k]) with step size h == H/n carried out using one Euler step followed by multiple explicit midpoint steps:

({{(Subscript[y, 1]), ==, (Subscript[y, 0])+ h f((Subscript[t, 0]),(Subscript[y, 0]))}, {(Subscript[y, 2]), ==, (Subscript[y, 0])+2 h f((Subscript[t, 1]),(Subscript[y, 1]))}, {(Subscript[y, 3]), ==, (Subscript[y, 1])+2 h f((Subscript[t, 2]),(Subscript[y, 2]))}, {⋮, ⋮, ⋮}, {(Subscript[y, n]), ==, (Subscript[y, n-2])+2 h f((Subscript[t, n-1]),(Subscript[y, n-1])).}})

If () is computed with  2(Subscript[n, k])-1 midpoint steps, then the method has a symmetric error expansion ([G65], [S70]).

Reformulation

Reformulation of () can be accomplished in terms of increments as

({{Δ (Subscript[y, 0]), ==, h f((Subscript[t, 0]),(Subscript[y, 0]))}, {Δ (Subscript[y, 1]), ==, 2h f((Subscript[t, 1]),(Subscript[y, 0])+Δ (Subscript[y, 0]))  - Δ (Subscript[y, 0])}, {Δ (Subscript[y, 2]), ==, 2h f((Subscript[t, 2]),(Subscript[y, 0])+(Δ (Subscript[y, 0])+ Δ (Subscript[y, 1])))  - Δ (Subscript[y, 1])}, {⋮, ⋮, ⋮}, {Δ (Subscript[y, n-1]), ==, 2h f((Subscript[t, n-1]),(Subscript[y, 0])+(Δ (Subscript[y, 0])+ Δ (Subscript[y, 1])+⋯+Δ (Subscript[y, n-2])))  - Δ (Subscript[y, n-2]).}})

Gragg's Smoothing Step

The smoothing step of Gragg has its historical origins in the weak stability of the explicit midpoint rule:

S (Subscript[y, h])(n)==1/4((Subscript[y, n-1])+2(Subscript[y, n])+(Subscript[y, n+1])).

In order to make use of (), the formulation () is computed with 2(Subscript[n, k]) steps. This has the advantage of increasing the stability domain and evaluating the function at the end of the basic step [HNW93].

Notice that because of the construction, a sum of increments is available at the end of the algorithm together with two consecutive increments. This leads to the following formulation:

S Δ (Subscript[y, h])(n)==S (Subscript[y, h])(n)-(Subscript[y, 0])==ΣΔ (Subscript[y, n])+1/4(Δ (Subscript[y, n])-Δ (Subscript[y, n-1])).

Moreover () has an advantage over () in finite-precision arithmetic because the values (Subscript[y, i]), which typically have a larger magnitude than the increments Δ (Subscript[y, i]), do not contribute to the computation.

Gragg's smoothing step is not of great importance if the method is followed by extrapolation, and Shampine proposes an alternative smoothing procedure that is slightly more efficient [SB83].

The method "ExplicitMidpoint" uses  2(Subscript[n, k])-1 steps and "ExplicitModifiedMidpoint" uses 2(Subscript[n, k]) steps followed by the smoothing step ().

Stability Regions

The following figures illustrate the effect of the smoothing step on the linear stability domain (carried out using the package FunctionApproximations.m).

Linear stability regions for (Subscript[T, i,i]),i==1,…,5 for the explicit midpoint rule (left) and the explicit midpoint rule with smoothing (right):

Since the precise stability boundary can be complicated to compute for an arbitrary base method, a simpler approximation is used. For an extrapolation method of order p, the intersection with the negative real axis is considered to be the point at which

The stability region is approximated as a disk with this radius and origin (0,0) for the negative half-plane.

Implicit Differential Equations

A generalization of the differential system () arises in many situations such as the spatial discretization of parabolic partial differential equations:

M y'(t)==f(t,y(t)),y((Subscript[t, 0]))==(Subscript[y, 0]).

where M is a constant matrix that is often referred to as the mass matrix.

Base methods in extrapolation that involve the solution of linear systems of equations can easily be modified to solve problems of the form ().

Multiple Linearly Implicit Euler Steps

Increments arise naturally in the description of many semi-implicit and implicit methods. Consider a succession of integration steps carried out using the linearly implicit Euler method for the system () with n == (Subscript[n, k]) and h==H/n.

({{(M-h J)Δ (Subscript[y, 0]), ==, h f((Subscript[t, 0]),(Subscript[y, 0]))}, {(Subscript[y, 1]), ==, (Subscript[y, 0])+ Δ (Subscript[y, 0])}, {(M - h J) Δ (Subscript[y, 1]), ==, h f((Subscript[t, 1]),(Subscript[y, 1]))}, {(Subscript[y, 2]), ==, (Subscript[y, 1])+ Δ (Subscript[y, 1])}, {(M - h J)Δ (Subscript[y, 2]), ==, h f((Subscript[t, 2]),(Subscript[y, 2]))}, {(Subscript[y, 3]), ==, (Subscript[y, 2])+Δ (Subscript[y, 2])}, {⋮, ⋮, ⋮}, {(M - h J) Δ (Subscript[y, n-1]), ==, h f((Subscript[t, n-1]),(Subscript[y, n-1]))}})

Here M denotes the mass matrix and J denotes the Jacobian of f:

The solution of the equations for the increments in () is accomplished using a single LU decomposition of the matrix M-h J followed by the solution of triangular linear systems for each right-hand side.

The desired result is obtained from () as

Reformulation

Reformulation in terms of increments as departures from (Subscript[y, 0]) can be accomplished as follows:

({{(M-h J) Δ (Subscript[y, 0]), ==, h f((Subscript[t, 0]),(Subscript[y, 0]))}, {(M-h J)Δ (Subscript[y, 1]), ==, h f((Subscript[t, 1]),(Subscript[y, 0])+Δ (Subscript[y, 0]))}, {(M-h J)Δ (Subscript[y, 2]), ==, h f((Subscript[t, 2]),(Subscript[y, 0])+(Δ (Subscript[y, 0])+ Δ (Subscript[y, 1])))}, {⋮, ⋮, ⋮}, {(M-h J)Δ (Subscript[y, n-1]), ==, h f((Subscript[t, n-1]),(Subscript[y, 0])+(Δ (Subscript[y, 0])+ Δ (Subscript[y, 1])+⋯+Δ (Subscript[y, n-2]))).}})

The result for (Subscript[y, n]) using () is obtained from ().

Notice that () and () are equivalent when J==0, M==I.

Multiple Linearly Implicit Midpoint Steps

Consider one step of the linearly implicit Euler method followed by multiple linearly implicit midpoint steps with n == 2 (Subscript[n, k]) and h==H/n, using the formulation of Bader and Deuflhard [BD83]:

({{(M - h J)Δ (Subscript[y, 0]), ==, h f((Subscript[t, 0]),(Subscript[y, 0]))}, {(Subscript[y, 1]), ==, (Subscript[y, 0])+Δ (Subscript[y, 0])}, {(M- h J) (Δ (Subscript[y, 1])-Δ (Subscript[y, 0])), ==, 2(h f((Subscript[t, 1]),(Subscript[y, 1]))-Δ (Subscript[y, 0]))}, {(Subscript[y, 2]), ==, (Subscript[y, 1])+Δ (Subscript[y, 1])}, {(M - h J) (Δ (Subscript[y, 2])-Δ (Subscript[y, 1])), ==, 2(h f((Subscript[t, 2]),(Subscript[y, 2]))-Δ (Subscript[y, 1]))}, {(Subscript[y, 3]), ==, (Subscript[y, 2])+Δ (Subscript[y, 2])}, {⋮, ⋮, ⋮}, {(M - h J)(Δ (Subscript[y, n-1])-Δ (Subscript[y, n-2])), ==, 2(h f((Subscript[t, n-1]),(Subscript[y, n-1]))-Δ (Subscript[y, n-2])).}})

If () is computed for 2(Subscript[n, k])-1 linearly implicit midpoint steps, then the method has a symmetric error expansion [BD83].

Reformulation

Reformulation of () in terms of increments can be accomplished as follows:

({{(M-h J) Δ (Subscript[y, 0]), ==, h f((Subscript[t, 0]),(Subscript[y, 0]))}, {(M-h J) (Δ (Subscript[y, 1])-Δ (Subscript[y, 0])), ==, 2(h f((Subscript[t, 1]),(Subscript[y, 0])+Δ (Subscript[y, 0]))-Δ (Subscript[y, 0]))}, {(M-h J)(Δ (Subscript[y, 2])-Δ (Subscript[y, 1])), ==, 2(h f((Subscript[t, 2]),(Subscript[y, 0])+(Δ (Subscript[y, 0])+ Δ (Subscript[y, 1])))-Δ (Subscript[y, 1]))}, {⋮, ⋮, ⋮}, {(M-h J)(Δ (Subscript[y, n-1])-Δ (Subscript[y, n-2])), ==, 2(h f((Subscript[t, n-1]),(Subscript[y, 0])+(Δ (Subscript[y, 0])+ Δ (Subscript[y, 1])+⋯+Δ (Subscript[y, n-2])))-Δ (Subscript[y, n-2])).}})

Smoothing Step

An appropriate smoothing step for the linearly implicit midpoint rule is [BD83]

S (Subscript[y, h])(n)==(1/2)((Subscript[y, n-1])+(Subscript[y, n+1])).

Bader's smoothing step () rewritten in terms of increments becomes

S Δ (Subscript[y, h])(n)==S (Subscript[y, h])(n)-(Subscript[y, 0])==ΣΔ (Subscript[y, n])+(1/2)(Δ(Subscript[y, n])-Δ(Subscript[y, n-1])).

The required quantities are obtained when () is run with 2(Subscript[n, k]) steps.

The smoothing step for the linearly implicit midpoint rule has a different role from Gragg's smoothing for the explicit midpoint rule (see [BD83] and [SB83]). Since there is no weakly stable term to eliminate, the aim is to improve the asymptotic stability.

The method "LinearlyImplicitMidpoint" uses  2(Subscript[n, k])-1 steps and "LinearlyImplicitModifiedMidpoint" uses  2(Subscript[n, k]) steps followed by the smoothing step ().

Polynomial Extrapolation in Terms of Increments

You have seen how to modify (Subscript[T, i,1]), the entries in the first column of the extrapolation table, in terms of increments.

However, for certain base integration methods, each of the (Subscript[T, i,j]) corresponds to an explicit Runge–Kutta method.

Therefore, it appears that the correspondence has not yet been fully exploited and further refinement is possible.

Since the Aitken–Neville algorithm () involves linear differences, the entire extrapolation process can be carried out using increments.

This leads to the following modification of the Aitken–Neville algorithm:

Δ (Subscript[T, i,j])==Δ (Subscript[T, i,j-1])+((Δ (Subscript[T, i,j-1])-Δ (Subscript[T, i-1,j-1]))/((((((Subscript[n, i])/(Subscript[n, i-j+1]))))^p)-1)),i==2,…,k,j==2,…,i.

The quantities Δ (Subscript[T, i,j])==(Subscript[T, i,j])-(Subscript[y, 0]) in () can be computed iteratively, starting from the initial quantities (Subscript[T, i,1]) that are obtained from the modified base integration schemes without adding the contribution from (Subscript[y, 0]).

The final desired value (Subscript[T, k,k]) can be recovered as Δ (Subscript[T, k,k])+(Subscript[y, 0]).

The advantage is that the extrapolation table is built up using smaller quantities, and so the effect of rounding errors from subtractive cancellation is reduced.

Implementation Issues

There are a number of important implementation issues that should be considered, some of which are mentioned here.

Jacobian Reuse

The Jacobian is evaluated only once for all entries (Subscript[T, i,1]) at each time step by storing it together with the associated time that it is evaluated. This also has the advantage that the Jacobian does not need to be recomputed for rejected steps.

Dense Linear Algebra

For dense systems, the LAPACK routines xyyTRF can be used for the LU decomposition and the routines xyyTRS for solving the resulting triangular systems [LAPACK99].

Adaptive Order and Work Estimation

In order to adaptively change the order of the extrapolation throughout the integration, it is important to have a measure of the amount of work required by the base scheme and extrapolation sequence.

A measure of the relative cost of function evaluations is advantageous.

The dimension of the system, preferably with a weighting according to structure, needs to be incorporated for linearly implicit schemes in order to take account of the expense of solving each linear system.

Stability Test

Extrapolation methods use a large basic step size that can give rise to some difficulties.

"Neither code can solve the Van der Pol equation problem in a straightforward way because of overflow..." [S87].

Two forms of stability test are used for the linearly implicit base schemes (for further discussion, see [HW96]).

One test is performed during the extrapolation process. Let (Subscript[err, j])==‖(Subscript[T, j,j-1])-(Subscript[T, j,j])‖.

In order to interrupt computations in the computation of (Subscript[T, 1,1]), Deuflhard suggests checking if the Newton iteration applied to a fully implicit scheme would converge.

For the linearly implicit Euler method this leads to consideration of

({{(M-h J)(Subscript[Δ, 0]), ==, h f((Subscript[t, 0]),(Subscript[y, 0]))}, {(M-h J)(Subscript[Δ, 1]), ==, h f((Subscript[t, 0]),(Subscript[y, 0])+(Subscript[Δ, 0]))-M (Subscript[Δ, 0]).}})

Notice that () differs from () only in the second equation. It requires finding the solution for a different right-hand side but no extra function evaluation.

For the implicit midpoint method, (Subscript[Δ, 0])==Δ (Subscript[y, 0]) and (Subscript[Δ, 1])==1/2(Δ (Subscript[y, 1])-Δ (Subscript[y, 0])), which simply requires a few basic arithmetic operations.

Increments are a more accurate formulation for the implementation of both forms of stability test.

Examples

Work-Error Comparison

For comparing different extrapolation schemes, consider an example from [HW96]:

t0 = π/6;
h0 = 1/10;
y0 = {2/(Sqrt[3])};
eqs = {y'[t]==(-y[t] Sin[t]+2 Tan[t]) y[t],y[t0]==y0};
exactsol=y[t]/.First[DSolve[eqs,y[t],t]]/.t->t0+h0;
idata =  {{eqs,y[t],t},h0,exactsol};

The exact solution is given by y(t)==1/cos(t).

Increment Formulation

This example involves an eighth-order extrapolation of "ExplicitEuler" with the harmonic sequence. Approximately two digits of accuracy are gained by using the increment-based formulation throughout the extrapolation process.

Approximately two decimal digits of accuracy are gained by using the increment-based formulation throughout the extrapolation process.

This compares the relative error in the integration data that forms the initial column of the extrapolation table for the previous example.

Reference values were computed using software arithmetic with 32 decimal digits and converted to the nearest IEEE double-precision floating-point numbers, where an ULP signifies a Unit in the Last Place or Unit in the Last Position.

({{ , (Subscript[T, 11]), (Subscript[T, 21]), (Subscript[T, 31]), (Subscript[T, 41]), (Subscript[T, 51]), (Subscript[T, 61]), (Subscript[T, 71]), (Subscript[T, 81])}, {Standard formulation, 0, -1 ULP, 0, 1 ULP, 0, 1.5 ULPs, 0, 1 ULP}, {Increment formulation
applied to the base method, 0, 0, 0, 0, 1 ULP, 0, 0, 1 ULP}})

Notice that the rounding-error model that was used to motivate the study of rounding-error growth is limited because in practice, errors in (Subscript[T, i,1]) can exceed 1 ULP.

The increment formulation used throughout the extrapolation process produces rounding errors in (Subscript[T, i,1]) that are smaller than 1 ULP.

Method Comparison

This compares the work required for extrapolation based on "ExplicitEuler" (red), the "ExplicitMidpoint" (blue), and "ExplicitModifiedMidpoint" (green).

All computations are carried out using software arithmetic with 32 decimal digits.

Order Selection

Select a problem to solve:

system = GetNDSolveProblem["Pleiades"];

Define a monitor function to store the order and the time of evaluation:

OrderMonitor[t_, method_NDSolve`Extrapolation]:=
Sow[{t,method["DifferenceOrder"]}];

Use the monitor function to collect data as the integration proceeds:

data =
 Reap[
NDSolve[system, Method->{"Extrapolation", Method->"ExplicitModifiedMidpoint"},"MethodMonitor":>OrderMonitor[T, NDSolve`Self]]
][[-1,1]];

Display how the order varies during the integration:

ListLinePlot[data]

Method Comparison

Select the problem to solve:

system=GetNDSolveProblem["Arenstorf"];

A reference solution is computed with a method that switches between a pair of "Extrapolation" methods, depending on whether the problem appears to be stiff:

sol = NDSolve[system,Method->"StiffnessSwitching",WorkingPrecision->32];

refsol = First[FinalSolutions[system,sol]];

Define a list of methods to compare:

methods = {{"ExplicitRungeKutta","StiffnessTest"->False},{"Extrapolation", Method->"ExplicitModifiedMidpoint","StiffnessTest"->False}};

The data comparing accuracy and work is computed using CompareMethods for a range of tolerances:

data=Table[Map[Rest,CompareMethods[system,refsol,methods,AccuracyGoal->tol,PrecisionGoal->tol]],{tol,4,14}];

The work-error comparison data for the methods is displayed in the following logarithmic plot, where the global error is displayed on the vertical axis and the number of function evaluations on the horizontal axis. Eventually the higher order of the extrapolation methods means that they are more efficient. Note also that the increment formulation continues to give good results even at very stringent tolerances:

ListLogLogPlot[Transpose[data],Joined->True,Axes->False,Frame->True,PlotStyle->{{Green},{Red}}]

Stiff Systems

One of the simplest nonlinear equations describing a circuit is Van der Pol's equation:

system = GetNDSolveProblem["VanderPol"];
vars = system["DependentVariables"];
time = system["TimeData"];

This solves the equations using "Extrapolation" with the "ExplicitModifiedMidpoint" base method with the default double-harmonic sequence 2, 4, 6, …. The stiffness detection device terminates the integration and an alternative method is suggested:

vdpsol = Flatten[vars /. NDSolve[system, Method->{"Extrapolation",Method->"ExplicitModifiedMidpoint"}]]

This solves the equations using "Extrapolation" with the "LinearlyImplicitEuler" base method with the default sub-harmonic sequence 2, 3, 4, …:

vdpsol = Flatten[vars /. NDSolve[system, Method->{"Extrapolation",Method->"LinearlyImplicitEuler"}]]

Notice that the Jacobian matrix is computed automatically (user-specifiable by using either numerical differences or symbolic derivatives) and appropriate linear algebra routines are selected and invoked at run time.

This plots the first solution component over time:

Plot[Evaluate[First[vdpsol]],Evaluate[time], Frame->True, Axes->False]

This plots the step sizes taken in computing the solution:

StepDataPlot[vdpsol]

High-Precision Comparison

Select the Lorenz equations:

system = GetNDSolveProblem["Lorenz"];

This invokes a bigfloat, or software floating-point number, embedded explicit Runge–Kutta method of order 9(8) [V78]:

Timing[
erksol = NDSolve[system,Method->{"ExplicitRungeKutta","DifferenceOrder"->9},WorkingPrecision->32];
]

This invokes the "Adams" method using a bigfloat version of LSODA. The maximum order of these methods is 12:

Timing[
adamssol =NDSolve[system,Method->"Adams", WorkingPrecision->32];
]

This invokes the "Extrapolation" method with "ExplicitModifiedMidpoint" as the base integration scheme:

Timing[
extrapsol = NDSolve[system, Method->{"Extrapolation", Method->"ExplicitModifiedMidpoint"},WorkingPrecision->32];
]

Here are the step sizes taken by the various methods. The high order used in extrapolation means that much larger step sizes can be taken:

methods = {"ExplicitRungeKutta", "Adams", "Extrapolation"};
solutions = {erksol,adamssol, extrapsol};
MapThread[StepDataPlot[#2, PlotLabel->#1]&,{methods , solutions}]

Mass Matrix - fem2ex

Consider the partial differential equation:

((∂u)/(∂t))== exp(t)(((∂^2)u)/(∂(x^2))), u(0,x) == sin(x) , u(t, 0) == u(t, π) == 0.

Given an integer n define h == π/(n+1) and approximate at (Subscript[x, k]) == k h with k == 0,…, n+1 using the Galerkin discretization,

u(t, (Subscript[x, k]))≈ (∑_(k=1)^n)(Subscript[c, k])(t) (Subscript[ϕ, k])(x)

where (Subscript[ϕ, k])(x) is a piecewise linear function that is 1 at (Subscript[x, k]) and 0 at (Subscript[x, j])≠(Subscript[x, k]).

The discretization () applied to () gives rise to a system of ordinary differential equations with constant mass matrix formulation as in (). The ODE system is the fem2ex problem in [SR97] and is also found in the IMSL library.

The problem is set up to use sparse arrays for matrices which is not necessary for the small dimension being considered, but will scale well if the number of discretization points is increased. A vector-valued variable is used for the initial conditions. The system will be solved over the interval [0,π]:

n = 9;
h = N[π/(n+1)];
amat = SparseArray[{Band[{1,1}]->2 h /3,Band[{1,2}]->h/6,Band[{2,1}]->h/6},{n+2, n+2},0.];
rmat = SparseArray[{Band[{1,1}]->-2/h,Band[{1,2}]->1/h,Band[{2,1}]->1/h},{n+2, n+2},0.];
vars = {y[t]};
eqs = {amat.y'[t]==rmat.(Exp[t]y[t])};
ics = {y[0]==Table[Sin[k h],{k,0,n+1}]};
system = {eqs,ics};
time = {t,0, π};

Solve the ODE system using "Extrapolation" with the "LinearlyImplicitEuler" base method. The "SolveDelayed" option is used to specify that the system is in mass matrix form:

sollim = NDSolve[system, vars, time,  Method->{"Extrapolation",Method->"LinearlyImplicitEuler"},
"SolveDelayed"->"MassMatrix",MaxStepFraction->1];

This plot shows the relatively large step sizes that are taken by the method:

StepDataPlot[sollim]

The default method for this type of problem is "IDA", which is a general purpose differential algebraic equation solver [HT99]. This method is much more general in scope than is necessary for this example, but serves for comparison purposes:

soldae = NDSolve[system, vars, time,MaxStepFraction->1];

The following plot clearly shows that a much larger number of steps is taken by the DAE solver:

StepDataPlot[soldae]

Define a function that can be used to plot the solutions on a grid:

PlotSolutionsOn3DGrid[{ndsol_}, opts___?OptionQ]:=
Module[{if, m,n, sols, tvals, xvals},
tvals = First[Head[ndsol]["Coordinates"]];
sols = Transpose[ndsol /. t->tvals];
m = Length[tvals];
n = Length[sols];
xvals = Range[0,n-1];
data = Table[{{Part[tvals,j],Part[xvals,i]},Part[sols,i,j]},{j,m},{i,n}];
data = Apply[Join,data];
if = Interpolation[data];
Plot3D[Evaluate[if[t,x]],Evaluate[{t,First[tvals],Last[tvals]}],Evaluate[{x,First[xvals],Last[xvals]}],PlotRange->All, Boxed->False, opts]
];

Display the solutions on a grid:

femsol = PlotSolutionsOn3DGrid[vars /. First[sollim],Ticks->{Table[i π,{i,0,1,1/2}],Range[0,n+1],Automatic},
AxesLabel->{"time  ","index",RawBoxes[RotationBox["solution\n",BoxRotation->Pi/2]]},Mesh->{19,9},MaxRecursion->0,PlotStyle->None]

Fine-Tuning

"StepSizeSafetyFactors"

As with most methods, there is a balance between taking too small a step and trying to take too big a step that will be frequently rejected. The option "StepSizeSafetyFactors"->{(Subscript[s, 1]),(Subscript[s, 2])} constrains the choice of step size as follows. The step size chosen by the method for order p satisfies:

(Subscript[h, n+1])==(Subscript[h, n])(Subscript[s, 1])((((Subscript[s, 2])(Tol/(‖(Subscript[err, n])‖))))^(1/(p+1))).

This includes both an order-dependent factor and an order-independent factor.

"StepSizeRatioBounds"

The option "StepSizeRatioBounds"->{(Subscript[sr, min]),(Subscript[sr, max])} specifies bounds on the next step size to take such that

"OrderSafetyFactors"

An important aspect in "Extrapolation" is the choice of order.

Each extrapolation step k has an associated work estimate (Subscript[𝒜, k]).

The work estimate for explicit base methods is based on the number of function evaluations and the step sequence used.

The work estimate for linearly implicit base methods also includes an estimate of the cost of evaluating the Jacobian, the cost of an LU decomposition, and the cost of backsolving the linear equations.

Estimates for the work per unit step are formed from the work estimate (Subscript[𝒜, k]) and the expected new step size to take for a method of order k (computed from ()): (Subscript[𝒲, k])==(Subscript[𝒜, k])/(Subscript[h, n+1]^k).

Comparing consecutive estimates, (Subscript[𝒲, k]) allows a decision about when a different order method will be more efficient.

The option "OrderSafetyFactors"->{(Subscript[f, 1]),(Subscript[f, 2])} specifies safety factors to be included in the comparison of estimates (Subscript[𝒲, k]).

An order decrease is made when (Subscript[𝒲, k-1])<(Subscript[f, 1])(Subscript[𝒲, k]).

An order increase is made when (Subscript[𝒲, k+1])<(Subscript[f, 2])(Subscript[𝒲, k]).

There are some additional restrictions, such as when the maximal order increase per step is one (two for symmetric methods), and when an increase in order is prevented immediately after a rejected step.

For a nonstiff base method the default values are {4/5,9/10} whereas for a stiff method they are {7/10,9/10}.

Option Summary

Options of the method "Extrapolation".

The default setting of (RefLink[Automatic, paclet:ref/Automatic]) for the option "ExtrapolationSequence" selects a sequence based on the stiffness and symmetry of the base method.

The default setting of (RefLink[Automatic, paclet:ref/Automatic]) for the option "MaxDifferenceOrder" bounds the maximum order by two times the decimal working precision.

The default setting of (RefLink[Automatic, paclet:ref/Automatic]) for the option "MinDifferenceOrder" selects the minimum number of two extrapolations starting from the order of the base method. This also depends on whether the base method is symmetric.

The default setting of (RefLink[Automatic, paclet:ref/Automatic]) for the option "OrderSafetyFactors" uses the values {7/10,9/10} for a stiff base method and {4/5,9/10} for a nonstiff base method.

The default setting of (RefLink[Automatic, paclet:ref/Automatic]) for the option "StartingDifferenceOrder" depends on the setting of "MinDifferenceOrder" (Subscript[p, min]). It is set to (Subscript[p, min])+1 or (Subscript[p, min])+2 depending on whether the base method is symmetric.

The default setting of (RefLink[Automatic, paclet:ref/Automatic]) for the option "StepSizeRatioBounds" uses the values {1/10,4} for a stiff base method and {1/50,4} for a nonstiff base method.

The default setting of (RefLink[Automatic, paclet:ref/Automatic]) for the option "StepSizeSafetyFactors" uses the values {9/10,4/5} for a stiff base method and {9/10,13/20} for a nonstiff base method.

The default setting of (RefLink[Automatic, paclet:ref/Automatic]) for the option "StiffnessTest" indicates that the stiffness test is activated if a nonstiff base method is used.

Options of the method "LinearlyImplicitEuler", "LinearlyImplicitMidpoint", and "LinearlyImplicitModifiedMidpoint".