Taylor Series Method for a first order ODE, not centered at $0$

numerical methodsordinary differential equationstaylor expansion

Given the following ODE,

$$\frac{{dy}}{{dx}}=\cos ({x})-\sin ({y})+{x}^{2}; \quad {y}\left({x}_{0}=-1\right)=y_0=3$$

I have to use the Taylor Series Method to compute the value of $y(x)$ at $x=-0.8$ with a Taylor's polynomial of second-order, with $h=x-x_0=0.1$.

Considering all this, how should this method be applied for solving this problem?


My attempt at a solution.

I'm not sure if this is the correct way to apply the method, but I have written Taylor's second-order polynomial centred at $x_0=-1.0$:

$$y(x) \approx y\left(x_{0}\right)+\left(x-x_{0}\right) y^{\prime}(x_0,y_0)+\frac{1}{2}\left(x-x_{0}\right)^{2} y^{\prime \prime}(x_0,y_0)=
\\=3.0+1.39918(x+1)+0.11333(x+1)^2 $$

And I have evaluated this $y(x)$ at $x=-0.8$, so $y(-0.8) \approx 3.28437$.

However, this doesn't match my textbook's solution, $3.2850$, neither Wolfram-Alpha's one, $3.28687$.

Would the method be applied this way or am I missing something?

Best Answer

As your step size is $0.1$, it appears that you are required to make 2 steps.

The equation to use is $y''=f_x+f_yf$, so one has to loop

x, y = -1.0, 3.0
h = 0.1
for k in range(5):
    Dy = cos(x)-sin(y)+x**2
    D2y = -sin(x)+2*x-cos(y)*Dy
    print(f"x:{x:10.7f}, y:{y:15.12f}: y':{Dy:15.12f}, y'':{D2y:15.12f}")
    x,y = x+h, y+h*Dy+0.5*h**2*D2y

with the output

x:-1.0000000, y: 3.000000000000: y': 1.399182297808, y'': 0.226650961014
x:-0.9000000, y: 3.141051484586: y': 1.431068799293, y'': 0.414395499366
x:-0.8000000, y: 3.286230342012: y': 1.480840620136, y'': 0.582734057905
x:-0.7000000, y: 3.437228074315: y': 1.546189950584, y'': 0.723329599331
x:-0.6000000, y: 3.595463717370: y': 1.623783569475, y'': 0.824028641900

For the efficient implementation of higher order Taylor methods one can apply Taylor arithmetic like in this answer.

Related Question