(√(abs(expr(ffun)/(d3/(h1^2)))))/10→hh
if hh=0: .01→hh
endif
©Initialize for solution loop
(expr(fphh)-expr(fmhh))/(2*hh)→amat[1,1]
big→err
©Loop to estimate derivative
for i,2,ntab
hh/con→hh
(expr(fphh)-expr(fmhh))/(2*hh)→amat[1,i]
con2→fac
for j,2,i
(amat[j-1,i]*fac-amat[j-1,i-1 ])/(fac-1)→amat[j,i]
con2*fac→fac
max(abs(amat[j,i]-amat[j-1,i]),abs(amat[j,i]-amat[j-1,i-1]))→errt
if errt≤err then
errt→err
amat[j,i]→dest
endif
endfor
if abs(amat[i,i]-amat[i-1,i-1])≥ safe*err:exit
endfor
return {dest,err}
endfunc
nder1() is called with the function name as a string, the evaluation point, and the initial step size. If the
step size is "auto", then nder1() tries to find a good step size based on the function and evaluation
point. nder1() returns a list with two elements. The first element is the derivative estimate, and the
second element is the error estimate.
nder1() is called as
nder1(fname,x,h)
where fname is the name of the function as a string in double quotes. x is the point at which to find the
derivative. h is a parameter which specifies a starting interval. If h is "auto" instead of a number, then
nder1() will try to automatically select a good value for h.
For example, to find the derivative of tan(x) at x = 1.0, with an automatic step size, use
nder1("tan",1,"auto")
which returns {3.42551882077, 3.7E-11}. The derivative estimate is 3.4255..., and the error estimate is
3.7E-11. To find the same derivative with a manual step size of 0.1, use
nder1("tan",1,.1)
which returns {3.42551882081,1.4E-12}.
6 - 30