11-11-2020, 11:11 AM

First order Numerical (explicit) Differentiation program for HP 35s

The companion program, 2nd order Derivative, can be found at https://www.hpmuseum.org/forum/thread-15875.html

This program is by Michael Lyons, and was inspired by the work by Alexis Zuleta.

OVERVIEW

This program is an alternative to the first order explicit derivative program found at https://www.hpmuseum.org/software/35derivp.htm

Zuleta uses this simple (forward distancing) approximation of the first derivative:

f'(x) ~ (f(x+h) - f(x)) / h (where h>0 : specifically, 1E-6 in his program)

D.Levy states that a centered differencing formula is more accurate, and may have practical advantages:

(It is generally the way some other calculators, such as TI-36x estimate f' at a point.)

f'(x) ~ (f(x+h)-f(x-h)) / 2h (D.Levy EQ 5.4 Introduction to Numerical Analysis)

I also chose to use an h value of 1E-6, which seems to work well.

This program is compact, uses a minimum of labels, and keeps the stack clean.

(The F label, shared by other programs, the D label and 1 variable 'D'.)

LISTING

F001 LBL F

F002 --> enter your function / eq here <-- (If F(x) has any trig func., be sure to set calc mode to Radians.)

F003 RTN

Be sure to have that RTN statement after the eq/function in F!

D001 LBL D

D002 INPUT D

D003 1E-6

D004 +

D005 XEQ D014

D006 RCL D

D007 1E-6

D008 -

D009 XEQ D014

D010 -

D011 2E-6 <-- note that is 2*h, not h (that's why it's different from step 3 and 7)

D012 /

D013 RTN

D014 STO X

D015 XEQ F001

D016 x<>y

D017 CLx

D018 R(down)

D019 RTN

EXAMPLE

If f(x)= x^4 + 5x^3 -21x^2

Calcuate f'(x) at x=4

Steps:

1. GTO F [ENTER]

2. -> [PRGM]

3. Go to line 2 of the F program and enter/edit the EQN to be x^4+5*x^3-21*x^2

4. Make sure there's only one EQN, and that you haven't accidentally deleted the RTN stmt.

5. Press [C/on] to exit program mode.

6. XEQ D [ENTER]

7. Displays D?

8. Enter the point to evaluate, in this case '4', then [R/S].

9. See RUNNING, then the result. In this case, 328.

Let's manually solve to confirm:

f'(x)=x^4 + 5x^3 -21x^2 | x=4

=4x^3 + 15x^2 -42x | x=4

=256 + 240 - 168

=328 <-- yes, it matches the calculator

Note:

This (and other) programs were written by me for the HP 35s to assist engineers in preparing/passing the NCEES FE/PE licensing exams.

The 35s is the only current HP/RPN allowed on the exam and competes directly with the TI-36x Pro and the Casio fx-991EX.

While each calculator has it's strengths, the 35s is the only programmable allowed. This, as well as RPN gives it a distinct potential advantage.

The companion program, 2nd order Derivative, can be found at https://www.hpmuseum.org/forum/thread-15875.html

This program is by Michael Lyons, and was inspired by the work by Alexis Zuleta.

OVERVIEW

This program is an alternative to the first order explicit derivative program found at https://www.hpmuseum.org/software/35derivp.htm

Zuleta uses this simple (forward distancing) approximation of the first derivative:

f'(x) ~ (f(x+h) - f(x)) / h (where h>0 : specifically, 1E-6 in his program)

D.Levy states that a centered differencing formula is more accurate, and may have practical advantages:

(It is generally the way some other calculators, such as TI-36x estimate f' at a point.)

f'(x) ~ (f(x+h)-f(x-h)) / 2h (D.Levy EQ 5.4 Introduction to Numerical Analysis)

I also chose to use an h value of 1E-6, which seems to work well.

This program is compact, uses a minimum of labels, and keeps the stack clean.

(The F label, shared by other programs, the D label and 1 variable 'D'.)

LISTING

F001 LBL F

F002 --> enter your function / eq here <-- (If F(x) has any trig func., be sure to set calc mode to Radians.)

F003 RTN

Be sure to have that RTN statement after the eq/function in F!

D001 LBL D

D002 INPUT D

D003 1E-6

D004 +

D005 XEQ D014

D006 RCL D

D007 1E-6

D008 -

D009 XEQ D014

D010 -

D011 2E-6 <-- note that is 2*h, not h (that's why it's different from step 3 and 7)

D012 /

D013 RTN

D014 STO X

D015 XEQ F001

D016 x<>y

D017 CLx

D018 R(down)

D019 RTN

EXAMPLE

If f(x)= x^4 + 5x^3 -21x^2

Calcuate f'(x) at x=4

Steps:

1. GTO F [ENTER]

2. -> [PRGM]

3. Go to line 2 of the F program and enter/edit the EQN to be x^4+5*x^3-21*x^2

4. Make sure there's only one EQN, and that you haven't accidentally deleted the RTN stmt.

5. Press [C/on] to exit program mode.

6. XEQ D [ENTER]

7. Displays D?

8. Enter the point to evaluate, in this case '4', then [R/S].

9. See RUNNING, then the result. In this case, 328.

Let's manually solve to confirm:

f'(x)=x^4 + 5x^3 -21x^2 | x=4

=4x^3 + 15x^2 -42x | x=4

=256 + 240 - 168

=328 <-- yes, it matches the calculator

Note:

This (and other) programs were written by me for the HP 35s to assist engineers in preparing/passing the NCEES FE/PE licensing exams.

The 35s is the only current HP/RPN allowed on the exam and competes directly with the TI-36x Pro and the Casio fx-991EX.

While each calculator has it's strengths, the 35s is the only programmable allowed. This, as well as RPN gives it a distinct potential advantage.