Taylor Series Method for ODE’s

← Numerical Methods

Source inspiration: (Mathew 2000-2019).

Description

The Taylor series method solves an initial value problem \(y' = f(t,y)\), \(y(t_0) = y_0\) on \([t_0, b]\) at the nodes \(t_n = t_0 + nh\). The Taylor method uses the ODE to compute higher derivatives analytically, then advances via a truncated Taylor series \(y_{n+1} = y_n + hy'_n + \frac{h^2}{2}y''_n + \cdots\). The method of order \(p\) keeps the terms through \(h^p\):

\[ y_{n+1} = y_n + h\,y'_n + \frac{h^2}{2!}\,y''_n + \cdots + \frac{h^p}{p!}\,y^{(p)}_n , \]

where each \(y^{(k)}_n\) comes from differentiating the ODE with the chain rule and evaluating at \((t_n, y_n)\): \(y' = f\), \(y'' = f_t + f_y\,f\), and so on. For this page’s \(f(t,y) = 1 - t\sqrt[3]{y}\), \(y'' = -\sqrt[3]{y} - \tfrac{t}{3}\,y^{-2/3}\,y'\).

Mathews assumes that \(f\) is continuous and satisfies a Lipschitz condition in \(y\); the method also needs the partial derivatives of \(f\) through order \(p-1\). Here \(f\) is smooth wherever \(y > 0\), and the solution stays positive on \([0, 5]\), decreasing after its peak to \(y(5) \approx 0.00812\).

In general, if \(f\) is in \(C^p\) near the solution (so \(y \in C^{p+1}[t_0, b]\)), the local truncation error is \(O(h^{p+1})\) and the global error \(|y(t_n) - y_n|\) is \(O(h^p)\), including at \(t = b\). On the runs of Case 1 (\(p = 3\)) and Case 2 (\(p = 4\)), halving \(h\) from \(5/60\) to \(5/120\) divides the largest node error by \(8.8\) and by \(17.9\), close to \(2^3 = 8\) and \(2^4 = 16\). The error in \(y(5)\) printed in the frames falls less regularly: over the same halving, by \(4.0\) for order 3 and \(580\) for order 4, partly because at \(m = 60\) the last steps lie in the shaded region.

The method is explicit, so stability limits its step as well as accuracy. On \(y' = \lambda y\) with real \(\lambda < 0\), one step multiplies \(y_n\) by \(1 + h\lambda + \cdots + (h\lambda)^p/p!\), which exceeds 1 in size once \(h|\lambda|\) passes \(2.513\) for \(p = 3\) or \(2.785\) for \(p = 4\). On this page’s problem \(\partial f/\partial y = -t/(3y^{2/3})\) reaches \(-41.3\) at \(t = 5\), where \(y\) is small, so coarse steps pass the limit in the tail (the shaded regions), and the runs with \(m = 12\) to \(36\) for order 3 (Case 1) and \(m = 12\) to \(32\) for order 4 (Case 2) leave the reference there. A higher order is no cure: at \(m = 16\) the order-3 run ends at \(y(5) \approx 0.156\) and the order-4 run at \(y(5) \approx -7666\). The method’s other cost is the derivatives, which must be redone for every new \(f\) and grow quickly with \(p\): this page’s \(y''''\) has eight terms over \(27y^{8/3}\).

Euler’s method is the case \(p = 1\), and Heun’s method and the Runge-Kutta method reach orders 2 and 4 from values of \(f\) alone; all three animate a step-refinement sweep on the same problem. Big “O” Truncation Error explains the \(O(h^p)\) notation, and Maclaurin and Taylor Series covers the series itself.

Animations

Each animation below repeats Mathews’ step-refinement sweep for the IVP \(y' = 1 - t\sqrt[3]{y}\), \(y(0)=1\) over \([0,5]\). Each frame is a complete Taylor-method run with \(m\) subintervals (\(h=5/m\)), for the 21 values of Mathews’ animations, \(m = 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 70, 80, 90, 100, 120, 150\), drawn over a fine-step reference solution and labelled with the computed \(y(5)\) and its error. Computed points below \(y=-0.3\) are marked by triangles on the bottom edge, and the run’s true minimum is printed. Here \(\sqrt[3]{y}\) is the real cube root, so runs that go negative stay real.

Julia source scripts that generated these animations are linked under each case.

Case 1 — Taylor order 3 step-refinement sweep, \(y' = 1 - t\sqrt[3]{y}\), \(y(0)=1\), \(m = 12\) to \(150\) subintervals

Behavior: With order \(p=3\), three derivative terms are used per step. The local truncation error is \(O(h^4)\) and the global error is \(O(h^3)\), the same order as a third-order Runge–Kutta method. The Taylor method requires explicit symbolic derivatives of the ODE right-hand side. The reference solution rises from \(y(0)=1\) to about \(1.4498\) near \(t=0.88\), then decays to \(y(5)=0.0081199\). For \(m=12\) through \(36\) the computed curve visibly leaves the reference in the tail: it ends at \(y(5)\approx-4.47\) for \(m=12\) and \(-109\) for \(m=14\), and at \(m=20\) it jumps from \(0.0068\) at \(t=4\) to \(1.22\) at \(t=4.25\) before ending at \(0.0895\). From \(m=40\) on, each run decreases steadily after its peak and stays within \(3\times10^{-4}\) of the reference at every node; at \(m=100\) (\(h=0.05\)) the largest node error is \(1.3\times10^{-5}\) and the error in \(y(5)\) is \(-1.2\times10^{-9}\). The cause is stability: \(\partial f/\partial y=-t/(3y^{2/3})\) reaches \(-41.3\) at \(t=5\), so for steps longer than about \(h=0.0609\) (\(m\le82\); here \(m=12\) to \(80\)), \(h\,|\partial f/\partial y|\) along the reference solution exceeds order-3 Taylor’s stability limit \(2.513\) before \(t=5\) (the shaded region in those frames); on \(y'=\lambda y\) with real \(\lambda<0\) the method amplifies errors once \(h|\lambda|\) exceeds this limit. For \(m=12\) to \(48\) the error at \(t=5\) is larger than at the last node before the shaded region. At \(m=80\) the shaded region begins at \(t\approx4.96\), inside the final step (which starts at \(t=4.9375\)), so no step is taken from inside it and every step still contracts errors; at least one step amplifies errors for each \(m\) from \(12\) to \(77\). For \(m=52\) to \(80\) the error in \(y(5)\) stays below \(3.1\times10^{-9}\); at \(m=12\) the shading starts at \(t\approx3.07\). For \(m=90\) to \(150\), \(h\,|\partial f/\partial y|\) stays below \(2.513\) up to \(t=5\). Mathews’ printed \(y(5)\) is reproduced to every printed digit for 19 of the 21 values of \(m\); the exceptions are \(m=12\) and \(14\), whose runs go negative before \(t=5\). There Mathews’ frames show different values (for example \(y(5)=0.1766603\) at \(m=12\)) because his program replaces each \(y^{k/3}\) by \(\operatorname{Sign}(y)\,|y|^{k/3}\), including even \(k\). For \(y<0\) that flips the sign of \(y^{2/3}\) and \(y^{4/3}\), so his higher derivatives are no longer those of the ODE. Applying his rule reproduces all 21 of his printed values; this page keeps the true real-cube-root derivatives.

Julia source

Taylor order-3 step-refinement sweep for y’ = 1 - t·y^(1/3), y(0)=1 on [0,5]: each frame is a complete run with m subintervals, m = 12 to 150, drawn over a gray reference curve that peaks near 1.45 at t ≈ 0.88 and decays to 0.0081 at t = 5. For m = 12 to 36 the run leaves the reference in the tail, dropping off the bottom of the plot for m = 12 and 14 and spiking to 1.22 at m = 20, and for m = 12 to 80 a shaded region marks where h·|∂f/∂y| along the reference curve exceeds 2.513 (at m = 80 only part of the final step); from m = 40 on the run lies on the reference, with y(5) = 0.0081199 at m = 150

Case 2 — Taylor order 4 step-refinement sweep, \(y' = 1 - t\sqrt[3]{y}\), \(y(0)=1\), \(m = 12\) to \(150\) subintervals

Behavior: With order \(p=4\), four derivative terms are used per step, all computed analytically. The local truncation error is \(O(h^5)\) and the global error is \(O(h^4)\), the same order as RK4. For \(m=12\) through \(32\) the computed curve visibly leaves the reference in the tail and goes negative, although the exact solution stays positive: \(y(5)\approx-7666\) for \(m=16\); at \(m=20\) the values turn negative at \(t=4.25\), reach about \(-10.4\) at \(t=4.5\) and end at \(y(5)\approx-5.25\); and \(y(5)\approx-0.081\) for \(m=32\). From \(m=36\) on, each run stays within \(2.7\times10^{-3}\) of the reference at every node (at \(m=36\) and \(40\) it still turns up once near the end, by about \(0.0015\) and \(0.0005\), too little to see), and from \(m=40\) on the error in \(y(5)\) falls at every refinement, to \(4.8\times10^{-12}\) at \(m=150\). At \(m=100\) (\(h=0.05\)) the largest node error is \(8.0\times10^{-7}\), more than 16 times smaller than the \(1.3\times10^{-5}\) of order 3. Stability is again the cause for the coarse runs. For steps longer than about \(h=0.0675\) (\(m\le74\); here \(m=12\) to \(70\)), \(h\,|\partial f/\partial y|\) along the reference solution exceeds order-4 Taylor’s stability limit \(2.785\) before \(t=5\) (the shaded region in those frames). For \(m=12\) to \(60\) each run has steps that genuinely amplify error, and the error at \(t=5\) is larger than at the last node before the shaded region. At \(m=70\) the shaded region, from \(t\approx4.91\), contains one step start (\(t\approx4.93\)), but that step’s actual error factor is \(0.92\) and no step of the run amplifies error, so the small rise from \(5.5\times10^{-10}\) at \(t\approx4.86\) to \(7.2\times10^{-10}\) at \(t=5\) is new truncation error rather than amplification. At \(m=12\) the shading starts at \(t\approx3.10\). For \(m=80\) to \(150\), \(h\,|\partial f/\partial y|\) stays below \(2.785\) up to \(t=5\). Mathews’ printed \(y(5)\) is reproduced to every printed digit for \(m=32\) to \(150\); for \(m=12\) to \(28\) the runs go negative before \(t=5\), and there, as in Case 1, his frames show different values (for example \(y(5)=0.0711898\) at \(m=20\)); the same rule, here also applied to \(y^{8/3}\), reproduces all 21 of his order-4 values.

Julia source

Taylor order-4 step-refinement sweep for y’ = 1 - t·y^(1/3), y(0)=1 on [0,5]: each frame is a complete run with m subintervals, m = 12 to 150, drawn over a gray reference curve that peaks near 1.45 at t ≈ 0.88 and decays to 0.0081 at t = 5. For m = 12 to 32 the run goes negative in the tail, dropping off the bottom of the plot for m = 12 to 28 (as low as -7751 at m = 16), and for m = 12 to 70 a shaded region marks where h·|∂f/∂y| along the reference curve exceeds 2.785; from m = 36 on the run lies on the reference, with y(5) = 0.0081199 at m = 150

References

Mathew, John H. 2000-2019. Numerical Analysis - Numerical Methods Modules. https://web.archive.org/web/20190808102217/http://mathfaculty.fullerton.edu/mathews/n2003/NumericalUndergradMod.html.