The absence of rectangular to polar, polar to rectangular and related functions on the HP 35s has already been discussed at length, and I believe that various routines are due to soon be included in the software library. Rather than wait, I attempted to go through the various threads to see if I could pull out the best routines for each function. However, I found it a bit tricky to follow the threads and various routines that were presented. To try to get a handle on things, I went back to the basics of the problem and tried to work my way forward. The following likely rehashes a lot of the previous discussion, and I make no claims of originality. So, at the risk of beating a dead horse (and exposing a blatant lack of understanding of some point or another), from the beginning.....
As I see things, there are seven basic functions related to the entry, display and conversion of complex numbers that the 35s lacks. For the sake of the following discussion, “Complex” means a complex number residing in a single stack level on the 35s, “Real Rectangular” means a complex number represented in rectangular form as two real values in two stack levels, and “Real Polar” means a complex number represented in polar form as two real values in two stack levels. The seven missing functions are:
- Complex to Real Rectangular Form conversion - Decomposition of a complex number into its real and imaginary components, with those values placed in the stack x and stack y registers, respectively.
- Complex to Real Polar Form conversion - Decomposition of a complex number into the magnitude and angle of its polar form, with those values placed in the stack x and stack y registers, respectively.
- Real Rectangular Form to Complex conversion - Formation of a complex number in stack x from real and imaginary components initially in the stack x and stack y registers, respectively.
- Real Polar Form to Complex conversion - Formation of a complex number in stack x from a magnitude and angle initially in the stack x and stack y registers, respectively.
- Real Polar to Real Rectangular Conversion - Conversion of a polar representation of complex number in stack x (magnitude) and stack y (angle) to a rectangular representation in stack x (real) and stack y (imaginary).
- Real Rectangular to Real Polar Conversion - Conversion of a rectangular representation of complex number in stack x (real) and stack y (imaginary) to a polar representation in stack x (magnitude) and stack y (angle).
- Complex Conjugate - Conversion of a complex number in stack x to its complex conjugate in stack x.
Re :a value representing the real component of a complex numberWith the above said, I believe that the previously described seven functions should perform as follows:
Im :a value representing the imaginary component of a complex number
Mag :a value representing the magnitude of a complex number when
expressed in polar form
Ang :a value representing the angle of a complex number when
expressed in polar form
A, B, C :specific pre-existing values in the stack
Re i Im :a complex number held in a single stack level displayed in
rectangular form
Mag / Ang :a complex number held in a single stack level displayed in
polar form
-- :the most recent value in the Last x register, to be overwritten
1. Complex to Real RectangularHaving come this far, I went ahead and developed seven routines to accomplish the above functions. I used many ideas and techniques developed in the previous discussion, and I don’t know if I exactly replicated any of the routines presented previously. If so, due credit is given to the original developer. I decided to place them all under one label, rather than having different labels for each. (In earlier threads, I found the labelling a bit confusing. Does Label P convert to Polar, from Polar, convert a complex number to real polar form, etc.?) I chose Label Z, for a couple of reasons. I intend for the program to be always resident on the calculator. Since Z is the last label alphabetically, I can easily remember that it is unavailable for general programming. Also, the letter Z is used to represent complex impedance in electric power engineering, which is my primary application for these functions, so it seemed natural to use it for this suite of functions. Each routine has an equation at the beginning that labels the function to be performed. It is set up to pause, display the function name, then execute the routine when each routine is called. It is not independent of flag 10, which is set to display the function label, then cleared in each routine. So flag 10 will be cleared after each routine, regardless of its setting prior to execution. The routines use only stack manipulation and equations, no general storage registers are used. With the above caveats, my program to implement the suite of Complex-Rectangular-Polar functions is as follows:Stack Before Stack After
t: C -> t: B
z: B -> z: A
y: A -> y: Im
x: Re i Im or Mag / Ang -> x: Re
Last x: -- -> Last x: Re i Im or Mag / Ang2. Complex to Real Polar
Stack Before Stack After
t: C -> t: B
z: B -> z: A
y: A -> y: Ang
x: Re i Im or Mag / Ang -> x: Mag
Last x: -- -> Last x: Re i Im or Mag / Ang3. Real Rectangular to Complex
Stack Before Stack After
t: B -> t: B
z: A -> z: B
y: Im -> y: A
x: Re -> x: Re i Im or Mag / Ang
Last x: -- -> Last x: Re4. Real Polar to Complex
Stack Before Stack After
t: B -> t: B
z: A -> z: B
y: Ang -> y: A
x: Mag -> x: Re i Im or Mag / Ang
Last x: -- -> Last x: Mag
5. Real Polar to Real RectangularStack Before Stack After
t: B -> t: B
z: A -> z: A
y: Ang -> y: Im
x: Mag -> x: Re
Last x: -- -> Last x: Mag6. Real Rectangular to Real Polar
Stack Before Stack After
t: B -> t: B
z: A -> z: A
y: Im -> y: Ang
x: Re -> x: Mag
Last x: -- -> Last x: Re7. Complex Conjugate
Stack Before Stack After
t: C -> t: C
z: B -> z: B
y: A -> y: A
x: Re i Im or Mag / Ang -> x: Re i -Im or Mag/ -Ang
Last x: -- -> Last x: Re i Im or Mag / Ang
Z001 LBL ZAnd, for what it’s worth,
Z002 SF 10 :Entry point for Complex to Rectangular
Z003 Eqn CPLX->RECT
Z004 PSE
Z005 CF 10
Z006 ABS
Z007 CLx
Z008 eqn ABS(LASTx)*SIN(ARG(LASTx))
Z009 eqn ABS(LASTx)*COS(ARG(LASTx))
Z010 RTN
Z011 SF 10 :Entry point for Complex to Polar
Z012 Eqn CPLX->POLAR
Z013 PSE
Z014 CF 10
Z015 ARG
Z016 LASTx
Z017 ABS
Z018 RTN
Z019 SF 10 :Entry point for Rectangular to Complex
Z020 Eqn RECT->CPLX
Z021 PSE
Z022 CF 10
Z023 ABS
Z024 Roll down
Z025 Roll down
Z026 Eqn LASTx+i*REGT
Z027 Eqn REGZ
Z028 Roll down
Z029 RTN
Z030 SF 10 :Entry point for Polar to Complex
Z031 Eqn POLAR->CPLX
Z032 PSE
Z033 CF 10
Z034 ABS
Z035 Roll Down
Z036 Roll Down
Z037 Eqn LASTx*COS(REGT)+i*LASTx*SIN(REGT)
Z038 Eqn REGZ
Z039 Roll Down
Z040 RTN
Z041 SF 10 :Entry point for Polar to Rectangular
Z042 Eqn POLAR->RECT
Z043 PSE
Z044 CF 10
Z045 ABS
Z046 Roll Down
Z047 Roll Down
Z048 Eqn LASTx*COS(REGT)+i*LASTx*SIN(REGT)
Z049 ENTER
Z050 Roll Down
Z051 Roll Down
Z052 Eqn ABS(REGZ)*SIN(ARG(REGZ))
Z053 Eqn ABS(REGT)*COS(ARG(REGT))
Z054 RTN
Z055 SF 10 :Entry point for Rectangular to Polar
Z056 Eqn RECT->POLAR
Z057 PSE
Z058 CF 10
Z059 ABS
Z060 CLx
Z061 LASTx
Z062 Roll Down
Z063 Roll Down
Z064 Eqn REGZ+i*REGT
Z065 ENTER
Z066 Roll Down
Z067 Roll Down
Z068 Eqn ARG(REGT)
Z069 Eqn ABS(REGT)
Z070 RTN
Z071 SF 10 :Entry point for Complex Conjugate
Z072 Eqn CPLX CONJUGATE
Z073 PSE
Z074 CF 10
Z075 ABS
Z076 CLx
Z077 Eqn SQ(ABS(LASTx))/LASTx
Z078 RTN
CK = F440
LN = 541