The built-in functions avgRC() and nDeriv() are fast, but they may not be accurate enough for some
applications. The avgRC() function can return, at best, an accuracy on the order of e
m
1/2
, where e
m
is
the machine accuracy. Since the 89/92+ uses 14 decimal digits, e
m
= 1E-14, so the best result we can
expect is about 1E-7. For nDeriv(), the best accuracy will be about e
m
2/3
, or about 5E-10. Neither of
these accuracies reach the 12-digit accuracy of which the 89/92+ is capable. It is also quite possible
that the actual error will be much worse. Our goal is to develop a routine which can calculate
derivatives with an accuracy near the full displayed resolution of the 89/92+.
Since the title of this tip is accurate numeric derivatives, I won't further consider avgRC(). Instead, I will
show how to get the best accuracy from nDeriv(), and also present code for an alternative method that
does even better.
Optimum results from nDeriv(): nder2()
nDeriv() finds the central difference over an interval h, where h defaults to 0.001. Since the limit of the
nDeriv() formula is the derivative, it makes sense that the smaller we make h, the better the derivative
result. Unfortunately, round-off errors dominate the result for too-small values of h. Therefore, there is
an optimum value of h for a given function and evaluation point. An obvious strategy is to evaluate the
formula with increasingly smaller values of h, until the absolute value of successive differences in f'(x)
begins to increase. This program, nder2(), shows this idea:
nder2(ff,xx)
func
©("f",x) find best f'(x) at x with central-difference formula
©6jun00 dburkett@infinet.com
local ff
1
,ff2,k,x,d
1
,d2,d3,h
©Build function expressions
ff&"(xx+h)"
→
ff
1
ff&"(xx-h)"
→
ff2
©Find first two estimates
.0
1→
h
(expr(ff
1
)-expr(ff2))/.02
→
d
1
.00
1→
h
(expr(ff
1
)-expr(ff2))/.002
→
d2
©Loop to find best estimate
for k,4,
1
4
1
0^
⁻
k
→
h
(expr(ff
1
)-expr(ff2))/(2*h)
→
d3
if abs(d3-d2)>abs(d2-d
1
) then
return d2
else
d2
→
d
1
d3
→
d2
endif
endfor
©Best not found; return last estimate
return d3
Endfunc
Call nder2() with the function name as a string. For example, to find the derivative of tan(x) at /2.01,
✜
the call is
6 - 28
Summary of Contents for TI-92+
Page 52: ...Component side of PCB GraphLink I O connector detail 1 41...
Page 53: ...LCD connector detail PCB switch side 1 42...
Page 54: ...Key pad sheet contact side Key pad sheet key side 1 43...
Page 55: ...Key cap detail 1 44...
Page 57: ...Component side of PCB with shield removed A detail view of the intergrated circuits 1 46...
Page 410: ...void extensionroutine2 void Credit to Bhuvanesh Bhatt 10 4...