Higher order Taylor method error

133 Views Asked by At

In numerical differential equation method Taylor high order 2 formula in initial value problem $ y'=f(t,y), y(a)=\alpha, a\leq t \leq b,$ $h$ is step size of $N=2$

$$w_0=\alpha, w_{i+1}=w_i + hf(t_i,w_i)+ \frac{h^2}{2}f'(t_i,w_i) $$

is it correct?

then problem is $ y'=\sin t + e^{-t}=f(t,y) , 0\leq t\leq1, y(0)=0$ with $h = 0.5 $

first $t=0$ i am calculating the $w_1$ this is correct $0.5$ ok

but $t=0.5$ my calculation is $w_2$ is $0.856807508$

but correct solution is $1.07xxxxxxx$

my algorithm is $w_2=0.5+0.5\times(f(0.5,0.5)+0.125\times f'(0.5,0.5))$

again calculating is $0.856807508$ by scientific calculator or r code

is there my calculation mistake?

1

There are 1 best solutions below

1
On

It always helps to stay as close to the theoretical formula as possible. In this case, $$ w_{k+1}=w_k+hf(t_k,w_k)+\frac12h^2(f_t(t_k,w_k)+f_y(t_k,w_k)f(t_k,w_k)) \\ =w_k+h\left(\left(1+\frac h2f_y(t_k,w_k)\right)f(t_k,w_k)+\frac h2f_t(t_k,w_k)\right) $$

def f(t,y): return np.sin(t)+np.exp(-t)
def f_t(t,y): return np.cos(t)-np.exp(-t)
def f_y(t,y): return 0

t,y,h=0,0,0.5;
while t < 1+0.1*h:
    t, y = t+h, y + h*( (1+0.5*h*f_y(t,y))*f(t,y) + 0.5*h*f_t(t,y) ); 
    print t,y

which prints out

0.5 0.5
1.0 1.0768595869306357
1.5 1.7030876580073921

In the formula you used you have an error in the inner factor 0.5*h, as instead of $0.5^2=0.25$ you got there $0.125=0.5^3$.