Post Reply 
A somewhat different Newton solver (HP35s)
09-25-2018, 11:46 AM (This post was last modified: 09-25-2018 01:54 PM by Ángel Martin.)
Post: #3
RE: A somewhat different Newton solver (HP35s)
Nicely done, it piqued my curiosity so I went ahead and jotted down the following 41Z version of the same concept.- About 30 steps in this proof of concept; which expects the function name in ALPHA, h in Y and the xo guess (a real value) in X.

Code:
01  LBL "ZNWT"   
02  ASTO 00    ; F.Name
03  X<>Y       
04  STO 01     ; h
05  CLX        ; ensure Im(z)=0
06  X<>Y   
07  LBL 00     ; loop
08  FS? 10     ; show value?
09  ZAVIEW     ; yes
10  ZSTO 01    ; save Zo = xo + 0i
11  XEQ IND 00 ; calculate f(Zo)
12  ZSTO 02    ; save f(Zo)
13  ZRCL 01    ; Zo
14  RCL 01     ; h
15  X<>Y    
16  XEQ IND 00 ; calculate f(Zo+i.h)
17  X<>Y       ; Im[f(Zo+i.h)]
18  RCL 01     ; h
19  /          ; f'(xo)
20  ST/ 04     ; divides Re[f(Zo)] by it
21  ST/ 05     ; divides Im[f(Zo)] (which should be zero anyway)
22  ZRCL 01    ; Zo
23  ZENTER^   
24  ZRCL 02    ; f(xo)/f'(xo)
25  Z-         ; x1
26  Z#W?       ; converged?
27  GTO 00     ; no, next iteration
28  CLA        ; yes, reset ALPHA
29  ARCL 00
30  END        ; done

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.

The function is to be programmed using 41Z functions (definitely a super-set of those in the 35S), as a complex equation.

To use Dieter's same example:

Code:
01  LBL "Z1"
02  Z^3
03  LASTZ
04  Z^2
05  LASTZ
06  Z+
07  Z-
08  ,5
09  +
10  END

Results:

ALPHA, "Z1", ALPHA
0.1, ENTER^, 2, XEQ "ZNWT" -> 1.451605963
0.1, ENTER^, 0, XEQ "ZNWT" -> 0.403031717
0.1, ENTER^, -2, XEQ "ZNWT"-> -0.854637680

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

Cheers,
ÁM

"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-25-2018 11:46 AM



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