HP Forums
HP35s and numerical differentiation - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: HP35s and numerical differentiation (/thread-2233.html)



HP35s and numerical differentiation - mcjtom - 10-05-2014 10:58 AM

What would be the simplest way of estimating a slope of tangent to function/expression (say, already stored in equation library) for a specified variable at a specified point?

I imagine I could write a programme that would use, say, two-point secant formula (or some higher precision formulas), but how would I parse a function from an equation library to it? Is there a simpler way?


RE: HP35s and numerical differentiation - Dieter - 10-05-2014 11:47 AM

(10-05-2014 10:58 AM)mcjtom Wrote:  What would be the simplest way of estimating a slope of tangent to function/expression (say, already stored in equation library) for a specified variable at a specified point?

There are several ways of evaluating the derivative of a function, a quite elegant one is shown below.

Quote:I imagine I could write a programme that would use, say, two-point secant formula (or some higher precision formulas), but how would I parse a function from an equation library to it? Is there a simpler way?

There is no way to access the equation list from within a user program. Sorry.

However, if the original function is defined in user code, another program may determine the derivative. A quite elegant way uses the 35s' complex mode. This has been discussed earlier in the old forum. A discussion with a working example in a 35s program can be found in this thread. Label F defines the function, label D calculates the derivative.

When entering the function F, be sure to use only commands the 35s can handle in complex mode, e.g. use x^ 0.5 instead of sqrt(x).

Dieter


RE: HP35s and numerical differentiation - Eddie W. Shore - 10-05-2014 04:43 PM

In addition to the user programs suggested, here is one that calculates the numerical derivate, using the Five Stencil Method.

Use the label U, the function is called at step 41.

Start with point to be calculated on the X stack.

Code:

U001 LBL U
U002 1E-3
U003 STO H
U004 2
U005 x
U006 R-down
U007 STO Z
U008 R-up
U009 +
U010 STO X
U011 XEQ U041
U012 +/-
U013 STO D
U014 RCL Z
U015 RCL+ H
U016 STO X
U017 XEQ U041
U018 8 
U019 x
U020 STO+ D
U021 RCL Z
U022 RCL- H
U023 STO X
U024 XEQ U041
U025 8
U026 x
U027 STO- D
U028 RCL Z
U029 RCL H
U030 2
U031 x
U032 -
U033 STO X
U034 XEQ U041
U035 STO+ D
U036 12
U037 RCLx H
U038 STO/ D
U039 VIEW D   // derivative
U040 RTN
U041  *** put f(X) **** here
...
U-last RTN

f'(X) = D = 1/(12H) * ( f(x-2H) - 8*f(x-H) + 8*f(x+H) - f(x+2H)) + H^4/30*f^(5)(o)
(error term omitted in calculation)

Source:
Burden, Richard L. and J. Douglas Faires. "Numerical Analysis 8th Edition" Thomson Brooks/Cole. Belton, CA 2005


RE: HP35s and numerical differentiation - Thomas Klemm - 10-05-2014 09:39 PM

(10-05-2014 04:43 PM)Eddie W. Shore Wrote:  \[\frac{f(x-2h)-8f(x-h)+8f(x+h)-f(x+2h)}{12h}\]

This expression can be transformed into:
\[\frac{4\frac{f(x+h)-f(x-h)}{2\cdot h}-\frac{f(x+2h)-f(x-2h)}{2\cdot 2h}}{4-1}\]

Now we can see that this is the 1st step of the Richardson extrapolation for \(\frac{f(x+h)-f(x-h)}{2\cdot h}\):

[Image: 4f6ecf3709be089073a3bd39aac3e6ce.png]

This can be extended similar to Romberg's method.


Cheers
Thomas