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
Post Reply 


Messages In This Thread
Valentin Albillo's "Boldly Going... Going Back to the roots" from 35S to 32SII / DM32 - Vincent Weber - 12-23-2023 05:07 PM



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