Question: how to write derivative of function inside the loop(for) ? " look in my code "

Hi,

I have this code to calculate taylor method but I do not know how to write the part about derivative of a function f  inside the loop for ??

restart;
f:=(t,y)->y-t^2+1:
eqn:=diff(y(t),t)=y(t)-t^2+1:
ex:=dsolve({eqn,y(0)=0.5},y(t)):
t[0]:=0:w[0]:=0.5:h:=0.2:ex[0]:=0.5:e[0]:=0:
for n from 1 to 10 do
t[n]:=n*h;ex[n]:=t[n]^2 + 2*t[n] + 1 - exp(t[n])/2;
w[n]:=w[n-1]+h*f(t[n-1],w[n-1])+((h^2/factorial(2))*(f(t[n-1],w[n-1])-2*t[n-1]));
e[n]:=abs(ex[n]-w[n]);
od:

printf(" i | t[i] |(Taylor)w[i] |(exact)y[i] |Error | \n ");for i from 0 to n-1 do
printf("%2.2f| %5.2f  | %5.6f| %5.6f  |  %5.6f | \n", i, t[i], w[i] ,ex[i],e[i]) ;
od;

Please Wait...