Post Reply 
(35S) 2nd order Derivative (at a point)
11-09-2020, 09:51 PM (This post was last modified: 11-13-2020 10:02 AM by trojdor.)
Post: #1
(35S) 2nd order Derivative (at a point)
2nd order Numerical (explicit) Differentiation program for HP 35s
This program is by Michael Lyons, and was inspired by the work by Alexis Zuleta.

OVERVIEW
This program is an addition to the first order explicit derivative program found at https://www.hpmuseum.org/software/35derivp.htm
By assigning this second order program to the G key, just below the D key used for the 1st order pgm,
(and sharing the same F / function,) it's easy to remember and use.

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)

(It's surprisingly efficient. Note that while D.Levy states that a centered differencing formula is more accurate,
in the real world testing I performed with a CD program I wrote, I could see no real benefit to replacing the Zuleta pgm.)

My d" program is based on the following 2nd order approximation of the second derivative:

f"(x) ~ (f(x+h)-2f(x)+f(x-h)) / h^2 (D.Levy EQ 5.6 Introduction to Numerical Analysis)

Note that the h value needs to be larger for the 2nd derivative approximation (I use 1E-3),
otherwise the calculator's precision limitation will cause the program to fail.

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!

G001 LBL G
G002 INPUT G
G003 STO X
G004 XEQ F001
G005 2
G006 *
G007 +/-
G008 x<>y
G009 1E-3
G010 +
G011 XEQ G019
G012 RCL G
G013 1E-3
G014 -
G015 XEQ G019
G016 1E-6 <-- note that is h^2, not h (that's why it's different from step 9 and 13)
G017 /
G018 RTN
G019 STO X
G020 XEQ F001
G021 x<>y
G022 CLx
G023 R(down)
G024 +
G025 RTN

EXAMPLE
(Updated for better example per AC suggestion...)

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 G [ENTER]
7. Displays G?
8. Enter the point to evaluate, in this case '4', then [R/S].
9. See RUNNING, then the result. In this case, 270.

Let's manually solve to confirm:
f'(x)=x^4 + 5x^3 -21x^2
=4x^3 + 15x^2 -42x
f"(x)=
=12x^2 + 30x -42 | x=4
=192 + 120 - 42
=270 <-- 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 HP is the only programmable allowed. This, as well as RPN gives it a distinct potential advantage.

ENTER > =
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(35S) 2nd order Derivative (at a point) - trojdor - 11-09-2020 09:51 PM



User(s) browsing this thread: 1 Guest(s)