Post Reply 
Valentin Albillo's "Boldly Going... Going Back to the roots" from 35S to 32SII / DM32
12-23-2023, 05:07 PM (This post was last modified: 12-23-2023 10:14 PM by Vincent Weber.)
Post: #1
Valentin Albillo's "Boldly Going... Going Back to the roots" from 35S to 32SII / DM32
Hi all,

Reading again Valentin's excellent article, featuring an efficient 35S program to find complex roots of an arbitrary equation (the build-in solver being unable to do so), I was thinking that it was a pity that my beloved DM32 could not do that, having no provision for complex registers or equations.

Or... was it really so ? I tried to adapt the program to the 32SII/DM32 limitations, and... I succeded ! Of course, the program uses many more steps, many more registers (you need to use 2 registers instead of one for each complex number, let alone the fact that you need to store intermediate results sometimes, since the stack is only 2-level depth and not 4, when dealing with complex numbers), more labels, and, the ugliest of all, you need to convert equations to RPN (32SII/DM32 equations are useless when dealing with complex numbers). It is a real pain, but it works, and it runs very fast on my DM32, much faster than on the 35S !

The program has also one slight improvement: since the 32SII can deal with indirect branching, unlike the 35S, I remplaced the XEQ F statements by XEQ(i). Juste store the equation routine number in i (e.g. 6 for F, 7 for G, 8 for H), and you can try many equations without erasing them or relabeling them.

When writing equations, use X for the real part of the unknown, and A for the imaginary part.
When supplying initial guesses, enter the imaginary part then the real part on the stack.

For the most part my program gives the same results than Valentin's, altough in some cases initial guesses leads to a different root - I have yet to figure out why.

Here is the program listing. Forgive the horrible formatting, it is coming straight out DM32 state file, which I can supply on request to DM32 users.

As supplied examples, LBL H holds example 4 (Leonardo di Pisa's equation), LBL F holds example 2 (polynom with complex coefficients) and LBL G holds example 3 (x^3-6x-2=0).

Long live the DM32 ! feedback welcome Smile

Code:
LBL A
  STO X
  R\down;
  STO A
  1E-4
  STO S
  x\sqr;
  STO T
  0.5
  STO Y
  LBL B
  XEQ\blpar;i\brpar;
  0
  RCL Y
  CMPLX\div;
  STO U
  R\down;
  STO B
  RCL S
  STO+ X
  XEQ\blpar;i\brpar;
  STO V
  R\down;
  STO C
  RCL S
  STO- X
  STO- X
  XEQ\blpar;i\brpar;
  STO W
  R\down;
  STO D
  R\up;
  RCL C
  RCL V
  CMPLX+
  RCL B
  RCL U
  CMPLX-
  0
  RCL T
  CMPLX\div;
  STO F
  R\down;
  STO E
  RCL C
  RCL V
  RCL D
  RCL W
  CMPLX-
  0
  RCL S
  STO+ X
  CMPLX\div;
  0
  RCL Y
  CMPLX\mul;
  STO W
  R\down;
  STO D
  RCL F
  RCL E
  RCL D
  RCL W
  CMPLX\div;
  STO V
  R\down;
  STO C
  R\up;
  RCL B
  RCL U
  CMPLX\mul;
  RCL D
  RCL W
  CMPLX\div;
  1
  -
  CMPLX+/-
  0
  RCL Y
  CMPLXy\powx;
  1
  -
  RCL C
  RCL V
  CMPLX\div;
  STO+ X
  R\down;
  STO+ A
  R\up;
  RCL A
  RCL X
  CMPLX\div;
  y,x\rarr;\theta;,r
  RCL T
  x<y?
  GTO B
  RCL A
  RCL X
  y,x\rarr;\theta;,r
  R\down;
  STO W
  SIN
  ABS
  RCL T
  x\le;y?
  GTO C
  RCL W
  COS
  ENTER
  ABS
  x\neq;0?
  \div;
  RCL A
  RCL X
  y,x\rarr;\theta;,r
  x<>y
  R\down;
  \mul;
  STO X
  LBL C
  RCL A
  RCL X
  RTN
  LBL H
  RCL A
  RCL X
  0
  3
  CMPLXy\powx;
  STO H
  R\down;
  STO G
  RCL A
  RCL X
  0
  2
  CMPLXy\powx;
  0
  2
  CMPLX\mul;
  RCL G
  RCL H
  CMPLX+
  STO H
  R\down;
  STO G
  RCL A
  RCL X
  0
  10
  CMPLX\mul;
  RCL G
  RCL H
  CMPLX+
  20
  -
  RTN
  LBL F
  RCL A
  RCL X
  0
  3
  CMPLXy\powx;
  3
  2
  CMPLX\mul;
  STO H
  R\down;
  STO G
  RCL A
  RCL X
  0
  2
  CMPLXy\powx;
  -2
  -1
  CMPLX\mul;
  RCL G
  RCL H
  CMPLX+
  STO H
  R\down;
  STO G
  RCL A
  RCL X
  -4
  -3
  CMPLX\mul;
  RCL G
  RCL H
  CMPLX+
  -8
  -6
  CMPLX+
  RTN
  LBL G
  RCL A
  RCL X
  0
  3
  CMPLXy\powx;
  -6
  RCL\mul; A
  -6
  RCL\mul; X
  CMPLX+
  2
  -
  RTN
Find all posts by this user
Quote this message in a reply
12-23-2023, 05:35 PM
Post: #2
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" from 35S to...
Related: (15C) Halley's Method
There are also some references that may be of interest to you.
Find all posts by this user
Quote this message in a reply
12-23-2023, 08:07 PM
Post: #3
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" from 35S to...
Here is the Plus42 version. Very similar to the original 35S version, but taking advantage of Plus42 pre-parsing of equations, and still using indirect adressing to easily switch equations. Rather than an RPN program, just write your equation (using X as the variable) in the editor, press STO then X to store it on the stack, the STO EQ to store it into variable EQ, et voilà! Works like a charm, exacts same results as the original, but in a blink of an eye, given Plus42 light speed.

It could be clearer to use LSTO instead of STO for all the intermediate variables, not to clutter the variable catalog.

Code:
00 { 241-Byte Prgm }
01▸LBL "SOLVC"
02 STO "X"
03 XSTR "ABS(SIN(L(W:ANGLE(X))))+0×G(W)"
04 PARSE
05 LSTO "EQ1"
06 XSTR "L(X:SGN(COS(W))×ABS(X))"
07 PARSE
08 LSTO "EQ2"
09 1ᴇ-4
10 STO "S"
11 X↑2
12 STO "T"
13 0.5
14 STO "Y"
15▸LBL 00
16 EVALN "EQ"
17 RCL÷ "Y"
18 STO "U"
19 RCL "S"
20 STO+ "X"
21 EVALN "EQ"
22 STO "V"
23 RCL "S"
24 STO- "X"
25 STO- "X"
26 EVALN "EQ"
27 STO "W"
28 RCL+ "V"
29 RCL- "U"
30 RCL÷ "T"
31 RCL "V"
32 RCL- "W"
33 RCL "S"
34 STO+ "X"
35 ÷
36 RCL× "Y"
37 STO "W"
38 ÷
39 STO "V"
40 RCL× "U"
41 RCL÷ "W"
42 1
43 -
44 +/-
45 RCL "Y"
46 Y↑X
47 1
48 -
49 RCL÷ "V"
50 STO+ "X"
51 RCL÷ "X"
52 ABS
53 RCL "T"
54 X<Y?
55 GTO 00
56 EVALN "EQ1"
57 X<Y?
58 EVALN "EQ2"
59 RCL "X"
60 VIEW "X"
61 RTN
62 END
Find all posts by this user
Quote this message in a reply
12-23-2023, 10:09 PM
Post: #4
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" from 35S to...
.
Hi, Vincent,

(12-23-2023 05:07 PM)Vincent Weber Wrote:  Reading again Valentin's excellent article, featuring an efficient 35S program to find complex roots of an arbitrary equation [...]

Thanks for your interest, Vincent, much appreciated, but don't you think it would have been proper to include a link to my article (Boldly Going - Going Back to the Roots), most especially since you're mentioning specific examples contained therein ?

Something like this: "Reading again Valentin's excellent article [...]"

Regards and Merry Xmas.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
12-23-2023, 10:15 PM (This post was last modified: 12-23-2023 10:15 PM by Vincent Weber.)
Post: #5
RE: Valentin Albillo's "Boldly Going... Going Back to the roots" from 35S to...
Hi Valentin,

You are absolutely right! I've just edited my first post accordingly.

Many thanks and cheers. Merry Christmas too!
Find all posts by this user
Quote this message in a reply
Post Reply 




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