Post Reply 
A somewhat different Newton solver (HP35s)
09-26-2018, 07:56 AM
Post: #4
RE: A somewhat different Newton solver (HP35s)
You don't have to execute the function twice since both, value and derivative are returned:
Code:
01 LBL "ZNWT"   ; h         x
02 ASTO 02      ;
03 ZTRP         ; x         h
04 ZSTO 00      ; R00: h    R01: x
05 LBL 00       ; loop
06 VIEW 01      ; view x
07 ZRCL 00      ; x         h
08 XEQ IND 02   ; f(x + ih)
09 X<>Y         ; ∆f(x)h    f(x)
10 /            ; ∆x/h
11 RCL 00       ; h         ∆x/h
12 *            ; ∆x
13 ST- 01       ; x' = x - ∆x
14 RND          ; ~∆x
15 X#0?         ; ∆x ~ 0 ?
16 GTO 00       ; loop
17 RCL 01       ; x
18 END          ; return x

Example:

2
ENTER
1E-9
XEQ "ZNWT"

2.000000000
1.642857143
1.487473705
1.453261463
1.451609751
1.451605963


(09-25-2018 11:46 AM)Ángel Martin Wrote:  The execution shows the successive values of the root if user flag 10 is set (a la PPC-ROM).
Convergence criteria always uses 9 decimal places - irrespective of the display FIX settings.

Feel free to change that to your needs: Add the check of user flag 10 and remove RND.

Quote:Supposedly more accurate results would be obtained with smaller values of h...

Usually 1e-9 will be small enough. But you might also use 1e-50.

Kind regards
Thomas
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) - Thomas Klemm - 09-26-2018 07:56 AM



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