I notice on my TI-30X Pro MathPrint...if I solve d/dx to =0 for (x^2 +7x +3)/ ^2, the solution found is most accurate when choosing an epsilon of 1E-05. Why is this the optimum choice? On my CASIO fx-991EX, the solution is more accurate, last digit shown is correctly rounded...wonder what epsilon is used, and what is different in it’s solve methodology...

Assuming calculator use central-difference derivative formula, this might answer your question.

Is there a general formula for estimating the step size h in numerical differentiation formulas ?
Example, estimate (ln(x))' at x=2:

lua> function D(x,h) return (log(x+h)-log(x-h))/(2*h) end

lua> for i=4,8 do print(i, D(2, 10^-i)) end

4 0.5000000004168335

5 0.5000000000088269

6 0.5000000000143777

7 0.49999999973682185

8 0.49999999696126407

Interestingly, optimal h for this example is also about 1e-5:

At the cost of more computation, we can use bigger h, and extrapolate for slope.

(similar to Romberg's integration, extrapolate from raw trapezoids, or rectangles)

lua> h = 1e-3

lua> d1 = D(2,h)

lua> d2 = D(2,h/2)

lua> d1, d2, d2+(d2-d1)/3

0.500000041666615 0.5000000104167235 0.5000000000000929

(03-26-2021 09:55 PM)Albert Chan Wrote: [ -> ]Assuming calculator use central-difference derivative formula, this might answer your question.

Is there a general formula for estimating the step size h in numerical differentiation formulas ?

Just my 2c.

This is a very good question. With numerical differentiation and finite difference stencils I've always used the cube-root of machine epsilon (MachEps). On 12 digit machines, this is 1E-4 and for 15 digit machines (no surprise) this is 1E-5.

As Albert says, 1E-5 should be about optimal.

See also

step size that explains the difficulty of choosing a step size. Let me add that an approximate to the optimal step can be empirically established.

- Rob

PS. (edit) you may also want to scale

h with the magnitude of the point(s) you're differentiating, otherwise you will end up with a slope that is closer to zero. For a 10 digit machine, let's take 1E-3, then what you want to do when differentiating at point

A is something like this:

h=1E-3

IF abs(A)>1 THEN h=h*abs(A)

The points X are at \( A\pm h \), but due to rounding you may want to do the following to get to X-A and then adjust H so it is exact:

X=A-h, h=A-X