Post Reply 
A somewhat different Newton solver (HP35s)
09-26-2018, 09:05 AM (This post was last modified: 09-26-2018 11:21 AM by Ángel Martin.)
Post: #5
RE: A somewhat different Newton solver (HP35s)
(09-26-2018 07:56 AM)Thomas Klemm Wrote:  You don't have to execute the function twice since both, value and derivative are returned:

Brilliant Thomas, many thanks for snapping me out of my stupor to see what was before my nose!

And so glad to see there's at least one more 41Z-literate person in the world ;-)
BTW nice move choosing R02 for the function name instead of R00 - this allows using the 41Z functions on ZR00, which uses "0" as default parameter so it's not required in the program.

Really impressive - although you must be using an older revision of the module, because with the latest one (the 'Deluxe" edition) the real part is stored in the lower register of the pair, i.e. ZSTO 00 stores Re(z) in R00 and Im(z) in R01

So re-writing the code for the 41Z-Deluxe conventions (transposing R00 and R01), and starting with h in Y, x guess in X:

Code:
01 LBL "ZNWT"   ; x         h
02 ASTO 02      ;
03 ZSTO 00      ; R01: h    R00: x
04 LBL 00       ; loop
05 VIEW 00      ; view x
06 ZRCL (00)    ; x         h
07 XEQ IND 02   ; f(x + ih)
08 X<>Y         ; ∆f(x)h    f(x)
09 /            ; ∆x/h
10 RCL 01       ; h         ∆x/h
11 *            ; ∆x
12 RND         ;~∆x
13 ST- 00       ; x' = x - ∆x
14 X#0?         ; ∆x ~ 0 ?
15 GTO 00       ; loop
16 RCL 00       ; x
17 END          ; return x

17 steps, nothing can beat that ;-)

Thanks much again.
Best,
ÁM

PS. As it turns out removing RND is not a good idea because some times the oscillation in the 10th. decimal place causes the test X#0? never to occur. This is a well-known behavior of the Newton method, so nothing new here...

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: A somewhat different Newton solver (HP35s) - Ángel Martin - 09-26-2018 09:05 AM



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