HP Forums

Full Version: (Plus42) Numerical Derivatives
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The Technical Applications book for the HP 27S and HP 19B (and can apply to the HP 17B outside of trigonometry) shows the numerical first and second derivative can be calculated by the formulas:

f ' (x) = (f(x+h) - f(x-h)) / (2 * h)

f ' ' (x) = (f(x + h) - 2 * f(x) + f(x - h)) / h^2

where h is sufficiently small, like 10^-5 to 10^-12.

FX(X): f(x) (insert f(x)

First Derivative:

F'X=(FX(X+H)-FX(X-H))÷(2×H)

Second Derivative:

F''X=(FX(X+H)-2×FX(X)+FX(X-H))÷SQ(H)

SQ: press by the key sequence [(shift)] (x^2)

': (ALPHA) [ ↓ ] (PUNC) [ ↓ ] ( ' )

Note: Radians mode


Examples

FIX 5 mode is set.

Example 1:

f(x) = 0.5 * cos(3*x)
x = π/4

FX(X):0.5×COS(3×X)
f'(x) ≈ -1.06066
f''(x) ≈ 3.18198

Example 2:

f(x) = (x^2 + 3*x + 5) / (4*x - 1)
x = 2

FX(X): (X^2+3×X+5)÷(4×X-1)
f'(x) ≈ -0.22449
f''(x) ≈ 0.54227


Functions with Variable Constants

It is easy to expand the user function FX to include variable constants. For example:

f(x) = -ln(cos(√(a*x)))
Calculate the value and first derivative at x = 0.11 and a = 0.46

Attach variable constants at the end of FX:

FX(X:A):-LN(COS(SQRT(A×X)))
F'X=(FX(X+H:A)-FX(X-H:A))÷(2×H)

f(x:a) ≈ 0.02552
f'(x:a) ≈ 0.23396
Reference URL's