Exemplo
> restart;
>
f:=x->sin(x);
evalf(cos(2));
>
deriv:=proc(f::procedure,x0::numeric,lim::posint,digitos::posint)
local h,i,s;
Digits:=digitos;
h:=0.1:
for i from 1 to lim do
h:=h*0.1;
s:=evalf((f(x0+h)-f(x0))/h):
printf("h =%10.8f %10.10f\n",h,s);
od:
end:
> deriv(f,2,7,8);
h = .01000000 -.4206870000
h = .00100000 -.4166000000
h = .00010000 -.4162000000
h = .00001000 -.4160000000
h = .00000100 -.4200000000
h = .00000010 -.4000000000
h = .00000001 0.0000000000
> deriv(f,2,7,10);
h = .01000000 -.4206863500
h = .00100000 -.4166014000
h = .00010000 -.4161920000
h = .00001000 -.4161500000
h = .00000100 -.4161000000
h = .00000010 -.4160000000
h = .00000001 -.4100000000
> deriv(f,2,7,20);
h = .01000000 -.4206863500
h = .00100000 -.4166014159
h = .00010000 -.4161923007
h = .00001000 -.4161513830
h = .00000100 -.4161472912
h = .00000010 -.4161468820
h = .00000001 -.4161468411
>