3  Taylor Methods for ODEs

Author
Affiliation

Enrico Bertolazzi

University of Trento, Department of Industrial Engineering

The explicit Euler method was obtained in the previous chapter by truncating the Taylor expansion of the exact solution after the linear term. Nothing forces us to stop there: if the solution is smooth enough, keeping more terms produces a one-step method of arbitrarily high order. The resulting family, the Taylor methods, is the natural reference against which Runge–Kutta methods are judged, and it is the only elementary way to reach high order using the information available at a single point.

Throughout this chapter we consider the scalar initial value problem

\left\{ \begin{aligned} y'(t) &= f(y(t),t), \\ y(a) &= y_a, \end{aligned} \right. \tag{3.1}

on [a,b], discretised on the uniform mesh

t_k = a+kh, \qquad h = \frac{b-a}{N}, \qquad k=0,1,\ldots,N,

and we assume that f has as many continuous partial derivatives as the expansions below require. The extension to systems is purely notational: every derivative becomes a vector and every partial derivative a Jacobian or a higher-order tensor.

3.1 Taylor Methods of Low Order

The three lowest-order Taylor methods are built the same way: truncate the Taylor expansion of the solution and replace the derivatives by their expressions in terms of f. Order one gives Euler, and each further term costs one more total derivative.

From Taylor’s Formula to Euler

Taylor’s formula with Lagrange remainder gives

y(t_{k+1}) = y(t_k)+y'(t_k)h+\frac{y''(\zeta_k)}{2}h^2, \qquad \zeta_k\in(t_k,t_{k+1}).

The differential equation supplies the first derivative, y'(t_k)=f(y(t_k),t_k), so

y(t_{k+1}) = y(t_k)+h f(y(t_k),t_k)+\frac{h^2}{2}y''(\zeta_k).

Neglecting the \mathcal O(h^2) remainder yields the explicit Euler method

y_{k+1}=y_k+h f(y_k,t_k),

whose local truncation error is \mathcal O(h^2) and whose global order is therefore one. The question addressed here is what happens when the remainder is pushed one or more orders further.

The Second-Order Taylor Method

Retaining one more term,

y(t_{k+1}) = y(t_k)+y'(t_k)h+\frac{y''(t_k)}{2}h^2+\frac{y'''(\zeta_k)}{6}h^3, \qquad \zeta_k\in(t_k,t_{k+1}),

raises an immediate difficulty: y''(t_k) is not directly available. It is, however, completely determined by the differential equation. Differentiating y'(t)=f(y(t),t) with respect to t and using the chain rule,

y''(t) = \frac{\mathrm{d}}{\mathrm{d}t}f(y(t),t) = \frac{\partial f(y(t),t)}{\partial t} + \frac{\partial f(y(t),t)}{\partial y}\,y'(t),

and replacing y'(t) by f(y(t),t) gives the computable expression

y''(t) = \frac{\partial f(y(t),t)}{\partial t} + \frac{\partial f(y(t),t)}{\partial y}\,f(y(t),t).

Substituting into the expansion and discarding the remainder produces the second-order Taylor method

\boxed{ y_{k+1} = y_k+h f(y_k,t_k) +\frac{h^2}{2} \left( \frac{\partial f(y_k,t_k)}{\partial t} + \frac{\partial f(y_k,t_k)}{\partial y}f(y_k,t_k) \right). } \tag{3.2}

NoteSymbolic differentiation

Building a Taylor method of order p requires the partial derivatives of f up to order p-1. Computing them by hand is laborious and error prone already for p=3. In practice one relies on a computer algebra system (Mathematica, Maple, SymPy) or on automatic differentiation, which evaluates the derivatives to machine accuracy without producing their symbolic expressions. The recursive formulation of Section 3.2 is precisely what such tools implement.

The Third-Order Taylor Method

One further term requires y'''. Differentiating the expression just obtained for y'',

\begin{aligned} y'''(t) &=\frac{\mathrm{d}}{\mathrm{d}t} \left( \frac{\partial f}{\partial t} +\frac{\partial f}{\partial y}f \right) \\ &=\frac{\partial^2 f}{\partial t^2} +2\frac{\partial^2 f}{\partial t\,\partial y}f +\frac{\partial^2 f}{\partial y^2}f^2 +\left(\frac{\partial f}{\partial y}\right)^{\!2}f +\frac{\partial f}{\partial t}\frac{\partial f}{\partial y}, \end{aligned}

all partial derivatives being evaluated at (y(t),t), with subscripts indicating differentiation with respect to the named variable.

Compact Notation

Writing

\begin{aligned} f_k &= f(y(t_k),t_k), & f_{t,k} &= \frac{\partial f(y(t_k),t_k)}{\partial t}, & f_{y,k} &= \frac{\partial f(y(t_k),t_k)}{\partial y}, \\[0.4em] f_{tt,k} &= \frac{\partial^2 f(y(t_k),t_k)}{\partial t^2}, & f_{ty,k} &= \frac{\partial^2 f(y(t_k),t_k)}{\partial t\partial y}, & f_{yy,k} &= \frac{\partial^2 f(y(t_k),t_k)}{\partial y^2}, \end{aligned}

the expansion of the exact solution becomes

\begin{aligned} y(t_{k+1}) &= y(t_k)+h f_k +\frac{h^2}{2}\left(f_{t,k}+f_{y,k}f_k\right) \\ &\quad +\frac{h^3}{6} \left( f_{tt,k}+2f_{ty,k}f_k+f_{yy,k}f_k^2 +f_{y,k}^2 f_k+f_{t,k}f_{y,k} \right) +\mathcal O(h^4). \end{aligned}

Dropping the remainder gives the third-order Taylor method

\boxed{ \begin{aligned} y_{k+1} &= y_k+h f_k +\frac{h^2}{2}\left(f_{t,k}+f_{y,k}f_k\right) \\ &\quad +\frac{h^3}{6} \left( f_{tt,k}+2f_{ty,k}f_k+f_{yy,k}f_k^2 +f_{y,k}^2 f_k+f_{t,k}f_{y,k} \right), \end{aligned} } \tag{3.3}

with all quantities now evaluated at the numerical point (y_k,t_k).

ImportantThe cost of order

Comparing Equation 3.2 and Equation 3.3 shows the structural weakness of the family: the number of elementary differentials grows combinatorially with the order (1, 2, 5, 15, … terms for orders 1, 2, 3, 4, …), exactly as the number of rooted trees in the Runge–Kutta order conditions. Each of them involves a different partial derivative of f.

Runge–Kutta methods were invented to buy the same order without any derivative of f, paying instead with a few extra evaluations of f per step. This is the comparison that motivates the next chapter.

3.2 A Recursive Formulation

The derivations above are instances of a single recursion that can be carried out to any order. Let y solve y'=f(y,t) and consider the Taylor expansion

y(t+h) = y(t)+h y'(t)+\frac{h^2}{2}y''(t)+\cdots +\frac{h^p}{p!}y^{(p)}(t)+\mathcal O(h^{p+1}). \tag{3.4}

We look for functions D_k(y,t) — independent of the particular solution — such that

y^{(k)}(t)=D_k\bigl(y(t),t\bigr), \qquad k=1,2,\ldots

Definition of the Functions D_k

The recursion starts from

D_1(y,t)=f(y,t),

since y'(t)=f(y(t),t). Assuming y^{(k)}(t)=D_k(y(t),t) and differentiating,

\begin{aligned} y^{(k+1)}(t) &=\frac{\mathrm{d}}{\mathrm{d}t}D_k\bigl(y(t),t\bigr) \\ &=\frac{\partial D_k(y(t),t)}{\partial t} +\frac{\partial D_k(y(t),t)}{\partial y}\,y'(t) \\ &=\frac{\partial D_k(y(t),t)}{\partial t} +\frac{\partial D_k(y(t),t)}{\partial y}\,f(y(t),t), \end{aligned}

which yields the recurrence

\boxed{ \left\{ \begin{aligned} D_1(y,t) &= f(y,t), \\ D_{k+1}(y,t) &= \frac{\partial D_k(y,t)}{\partial t} +\frac{\partial D_k(y,t)}{\partial y}f(y,t), \qquad k=1,2,\ldots \end{aligned} \right. } \tag{3.5}

Substituting into Equation 3.4 gives the Taylor method of order p

\boxed{ \left\{ \begin{aligned} y_{k+1} &= y_k+h\,y'_k+\frac{h^2}{2!}y''_k+\cdots+\frac{h^p}{p!}y^{(p)}_k, \\[0.4em] y^{(j)}_k &= D_j(y_k,t_k),\qquad j=1,\ldots,p. \end{aligned} \right. } \tag{3.6}

Its local truncation error is \mathcal O(h^{p+1}) and, under the usual Lipschitz hypothesis on the increment function, the global order is p.

Example: f(y,t)=t+y+ty

For the problem

\left\{ \begin{aligned} y' &= t+y+ty, \\ y(a) &= y_a, \end{aligned} \right.

the recurrence Equation 3.5 gives

\begin{aligned} D_1 &= t+y+ty, \\[0.5em] D_2 &= \frac{\partial D_1}{\partial t}+\frac{\partial D_1}{\partial y}D_1 = (y+1)+(t+1)(t+y+ty) \\ &= (y+1)t^2+(2y+1)t+2y+1, \\[0.5em] D_3 &= (y+1)t^3+(3y+2)t^2+(6y+4)t+4y+1, \\[0.5em] D_4 &= (y+1)t^4+(4y+3)t^3+(12y+9)t^2+(16y+8)t+10y+4, \\[0.5em] D_5 &= (y+1)t^5+(5y+4)t^4+(20y+16)t^3+(40y+25)t^2+(50y+28)t+26y+8, \\[0.5em] D_6 &= (y+1)t^6+(6y+5)t^5+(30y+25)t^4+(80y+56)t^3 \\ &\quad +(150y+98)t^2+(156y+76)t+76y+28. \end{aligned}

Using these six functions in Equation 3.6 produces a sixth-order method for this particular equation. Note how quickly the expressions grow even for a right-hand side as simple as a bilinear polynomial: this growth is the price of eliminating y' at every stage of the recursion.

3.3 An Improved Recursion

The explosion observed above is largely an artefact of insisting that D_k depend on (y,t) only. Each substitution y'\mapsto f(y,t) is immediately followed by a differentiation, which reintroduces the same subexpressions in a more complicated form.

If instead the derivatives already computed are kept as independent arguments, the recursion stays simple. Consider

\begin{aligned} {\color{red}y'(t)} &= f(y(t),t) = D_1(y(t),t), \\[0.4em] {\color{blue}y''(t)} &= \frac{\mathrm{d}}{\mathrm{d}t}D_1(y(t),t) = \frac{\partial D_1}{\partial t} +\frac{\partial D_1}{\partial y}{\color{red}y'(t)} = D_2\bigl(y(t),y'(t),t\bigr), \\[0.4em] y'''(t) &= \frac{\mathrm{d}}{\mathrm{d}t}D_2\bigl(y(t),y'(t),t\bigr) \\ &= \frac{\partial D_2}{\partial t} +\frac{\partial D_2}{\partial y}{\color{red}y'(t)} +\frac{\partial D_2}{\partial y'}{\color{blue}y''(t)} = D_3\bigl(y(t),y'(t),y''(t),t\bigr), \end{aligned}

and so on. This suggests functions

D_k\bigl(y,y',\ldots,y^{(k-1)},t\bigr)

such that, along the exact solution,

y^{(k)}(t)=D_k\bigl(y(t),y'(t),\ldots,y^{(k-1)}(t),t\bigr),

defined by the recurrence

\boxed{ \left\{ \begin{aligned} D_1(y,t) &= f(y,t), \\[0.3em] D_{k+1} &= \frac{\partial D_k}{\partial t} +\sum_{j=0}^{k-1} \frac{\partial D_k}{\partial y^{(j)}}\,y^{(j+1)}, \qquad k=1,2,\ldots \end{aligned} \right. } \tag{3.7}

with the convention y^{(0)}=y. The derivatives y'_k,y''_k,\ldots are evaluated in sequence at each mesh point, so the right-hand side of the recurrence is always available.

Example: f(y,t)=t+y+ty Revisited

For the same equation, and omitting the arguments,

\begin{aligned} D_1 &= t+y+ty, \\[0.5em] D_2 &= \frac{\partial D_1}{\partial t}+\frac{\partial D_1}{\partial y}y' = (t+1)y'+y+1, \\[0.5em] D_3 &= \frac{\partial D_2}{\partial t} +\frac{\partial D_2}{\partial y}y' +\frac{\partial D_2}{\partial y'}y'' = (t+1)y''+2y', \\[0.5em] D_4 &= (t+1)y'''+3y'', \\[0.5em] D_5 &= (t+1)y^{(4)}+4y''', \\[0.5em] D_6 &= (t+1)y^{(5)}+5y^{(4)}. \end{aligned}

The pattern D_{k+1}=(t+1)y^{(k)}+k\,y^{(k-1)} for k\ge2 is evident, and the sixth-order method becomes

\boxed{ \left\{ \begin{aligned} y_{k+1} &= y_k+h y'_k+\frac{h^2}{2!}y''_k+\frac{h^3}{3!}y'''_k +\frac{h^4}{4!}y^{(4)}_k+\frac{h^5}{5!}y^{(5)}_k +\frac{h^6}{6!}y^{(6)}_k, \\[0.5em] y'_k &= (t_k+1)y_k+t_k, \\ y''_k &= (t_k+1)y'_k+y_k+1, \\ y'''_k &= (t_k+1)y''_k+2y'_k, \\ y^{(4)}_k &= (t_k+1)y'''_k+3y''_k, \\ y^{(5)}_k &= (t_k+1)y^{(4)}_k+4y'''_k, \\ y^{(6)}_k &= (t_k+1)y^{(5)}_k+5y^{(4)}_k. \end{aligned} \right. }

Each derivative now costs a couple of arithmetic operations instead of the evaluation of a polynomial of growing degree: the same sixth-order accuracy is obtained at a small fraction of the cost of Equation 3.6.

Numerical Check of the Order

The following experiment integrates y'=t+y+ty with y(0)=1 on [0,1] using the improved recursion truncated at orders p=2,4,6, and compares the error at t=1 against the reference solution produced by a stringent adaptive solver.

taylor_step <- function(t, y, h, p) {
  d <- numeric(p)              # d[j] = y^(j)
  d[1] <- (t + 1) * y + t
  if (p >= 2) d[2] <- (t + 1) * d[1] + y + 1
  if (p >= 3) for (k in 3:p) d[k] <- (t + 1) * d[k-1] + (k-1) * d[k-2]
  y + sum(h^(1:p) / factorial(1:p) * d)
}

taylor_solve <- function(N, p, t0 = 0, y0 = 1, T = 1) {
  h <- (T - t0) / N; t <- t0; y <- y0
  for (k in 1:N) { y <- taylor_step(t, y, h, p); t <- t + h }
  y
}

# reference solution: y' = (1+t) y + t, solved to near machine accuracy
ref <- deSolve::ode(y = 1, times = c(0, 1),
                    func = function(t, y, parms) list((1 + t) * y + t),
                    parms = NULL, rtol = 1e-14, atol = 1e-14)[2, 2]

Ns  <- 2^(2:7)
err <- expand.grid(N = Ns, p = c(2, 4, 6))
err$error <- mapply(function(N, p) abs(taylor_solve(N, p) - ref), err$N, err$p)
err$h <- 1 / err$N

tab <- reshape2::dcast(err, N ~ p, value.var = "error")
tab[-1] <- lapply(tab[-1], formatC, format = "e", digits = 2)
knitr::kable(
  tab,
  col.names = c("$N$", "$p=2$", "$p=4$", "$p=6$"),
  align = "r",
  caption = "Absolute error at $t=1$ as a function of the number of steps."
)
Absolute error at t=1 as a function of the number of steps.
N p=2 p=4 p=6
4 3.44e-01 8.51e-03 1.34e-04
8 1.05e-01 6.77e-04 2.77e-06
16 2.90e-02 4.78e-05 4.98e-08
32 7.62e-03 3.17e-06 8.35e-10
64 1.95e-03 2.04e-07 1.44e-11
128 4.94e-04 1.30e-08 1.16e-12
# observed orders from consecutive refinements
ord <- do.call(rbind, lapply(c(2, 4, 6), function(p) {
  e <- err$error[err$p == p]
  data.frame(p = p, observed = c(NA, log2(head(e, -1) / tail(e, -1))))
}))
ord$N <- rep(Ns, times = 3)
ggplot2::ggplot(err, ggplot2::aes(h, error, colour = factor(p))) +
  ggplot2::geom_line() + ggplot2::geom_point() +
  ggplot2::scale_x_log10() + ggplot2::scale_y_log10() +
  ggplot2::labs(x = "h", y = "error at t = 1", colour = "order p") +
  ggplot2::theme_minimal()
Figure 3.1: Error at t=1 for the Taylor methods of order 2, 4 and 6.
knitr::kable(
  reshape2::dcast(ord, N ~ p, value.var = "observed"),
  col.names = c("$N$", "$p=2$", "$p=4$", "$p=6$"),
  digits = 3, align = "r",
  caption = "Observed order $\\log_2(e_{N}/e_{2N})$ between consecutive refinements."
)
Observed order \log_2(e_{N}/e_{2N}) between consecutive refinements.
N p=2 p=4 p=6
4 NA NA NA
8 1.709 3.652 5.595
16 1.856 3.826 5.799
32 1.929 3.913 5.898
64 1.965 3.957 5.853
128 1.983 3.978 3.633

The observed slopes approach the nominal orders 2, 4 and 6. The last entry of the sixth-order column degrades not because the method fails, but because the error has reached the accuracy of the reference solution itself: with p=6 and N=128 the approximation is already as good as the yardstick used to measure it. This is the usual warning that an order verification is meaningful only in the window between the pre-asymptotic transient and the accuracy floor of the comparison.

Summary

  • Repeated differentiation of the ODE expresses y'', y''', … in terms of f and its partial derivatives; truncating the Taylor series at order p gives a one-step method of order p.
  • The method reaches any order using information at a single point, but requires the derivatives of f: it is practical only with symbolic or automatic differentiation.
  • The recursion Equation 3.5 is the straightforward formulation; the improved recursion Equation 3.7 keeps the previously computed derivatives as arguments and avoids the combinatorial growth of the expressions.
  • The comparison is what motivates Runge–Kutta methods: the same order, no derivatives of f, at the price of several evaluations of f per step.