01-26-2019, 12:43 AM

I would like to know what program(s) are best for Complex Number and Polar/Rectangular and related forms decomposition for the 35S.

Thank you.

Thank you.

HP Forums > HP Calculators (and very old HP Computers) > General Forum > Best Pol/Rect and Complex Number Decomp for 35S

You're currently viewing a stripped down version of our content. View the full version with proper formatting.

01-26-2019, 12:43 AM

I would like to know what program(s) are best for Complex Number and Polar/Rectangular and related forms decomposition for the 35S.

Thank you.

Thank you.

01-26-2019, 02:21 AM

(01-26-2019 12:43 AM)Matt Agajanian Wrote: [ -> ]I would like to know what program(s) are best for Complex Number and Polar/Rectangular and related forms decomposition for the 35S.

Thank you.

Nice ->R and ->P programs from Pauli here:

http://www.hpmuseum.org/cgi-sys/cgiwrap/...i?read=983

01-26-2019, 03:29 AM

Thanks! Even though I picked this up several years ago, nice to know its stood the test of time to remain an excellent option.

01-26-2019, 03:37 AM

(01-26-2019 02:21 AM)rprosperi Wrote: [ -> ](01-26-2019 12:43 AM)Matt Agajanian Wrote: [ -> ]I would like to know what program(s) are best for Complex Number and Polar/Rectangular and related forms decomposition for the 35S.

Thank you.

Nice ->R and ->P programs from Pauli here:

http://www.hpmuseum.org/cgi-sys/cgiwrap/...i?read=983

Please refresh my memory and clarify what should be on the stack before I run each routine.

Thanks

Thanks

01-26-2019, 10:40 AM

(01-26-2019 03:37 AM)Matt Agajanian Wrote: [ -> ](01-26-2019 02:21 AM)rprosperi Wrote: [ -> ]Nice ->R and ->P programs from Pauli here:

http://www.hpmuseum.org/cgi-sys/cgiwrap/...i?read=983

Please refresh my memory and clarify what should be on the stack before I run each routine.

Thanks

Thanks

Looking at the code, program P expects Y=y, X=x, and returns Y=θ, X=r. Vice versa for program R.

01-26-2019, 01:04 PM

(01-26-2019 10:40 AM)ijabbott Wrote: [ -> ]Looking at the code, program P expects Y=y, X=x, and returns Y=θ, X=r. Vice versa for program R.

Yes, and if you look closely you'll see these routines preserve the stack (incl LastX) and flags, so they act like built-in functions. Nice!

01-26-2019, 04:23 PM

(01-26-2019 01:04 PM)rprosperi Wrote: [ -> ]...if you look closely you'll see these routines preserve the stack (incl LastX) and flags...

Yes for the stack and flags, but No regarding LastX. Which is not preserved – on exit it contains a complex number or a vector, respectively.

But it can be done. The following modified versions also preserve LastX:

Code:

`P001 LBL P`

P002 FS? 10

P003 GTO P011

P004: ABS

P005 X<>Y

P006 R↓

P007 R↓

P008 eqn ARG(LASTx+i*REGZ)

P009 eqn ABS(LASTx+i*REGT)

P010 RTN

P011: CF 10

P012 XEQ P004

P013 SF 10

P014 RTN

R001 LBL R

R002 FS? 10

R003 GTO R011

R004: ABS

R005 X<>Y

R006 R↓

R007 R↓

R008 eqn LASTx*SIN(REGZ)

R009 eqn LASTx*COS(REGT)

R010 RTN

R011: CF 10

R012 XEQ R004

R013 SF 10

R014 RTN

The R routine is even one step shorter. ;-)

Equations in programs really are a nice feature of the 35s. They simply return the result in X and push the stack by one level, while no other stack registers – including LastX – are affected. So these programs simply move the original X to LastX (by means of the ABS command in line 004) before they finally return the two results in Y and X.

For those who are not that familiar with the 35s equation mode: REGZ and REGT are entered by pressing the [R↓] key and then selecting the respective register X, Y, Z or T from the menu.

Stack diagram for →P:

Code:

`T: t t`

Z: z z

Y: y => θ

X: x r

L: ? x

Stack diagram for →R:

Code:

`T: t t`

Z: z z

Y: θ => y

X: r x

L: ? r

Finally, if the state of flag 10 does not have to be preserved the code can be even shorter. In this case remove line 011...014 and replace line 002...003 with "CF 10".

Dieter

01-26-2019, 07:02 PM

Excellent, Dieter, as always!

01-26-2019, 07:17 PM

(01-26-2019 07:02 PM)Gene Wrote: [ -> ]Excellent, Dieter, as always!

And cool too! Thanks.

01-26-2019, 08:49 PM

(01-26-2019 12:43 AM)Matt Agajanian Wrote: [ -> ]I would like to know what program(s) are best for Complex Number and Polar/Rectangular and related forms decomposition for the 35S.

Here is my attempt at a complex decomposition routine:

Code:

`C001 LBL C`

C002 FS? 10

C003 GTO C014

C004 ABS

C005 x≠0?

C006 GTO C009

C007 ENTER

C008 RTN

C009: eqn SGN(SIN(ARG(LASTx)))*ABS(LASTx-SQ(REGX)/LASTx)/2

C010 X<>Y

C011 R↓

C012 eqn SGN(COS(ARG(LASTx)))*ABS(LASTx+SQ(REGT)/LASTx)/2

C013 RTN

C014: CF 10

C015 XEQ C004

C016 SF 10

C017 RTN

Stack diagram:

Code:

`T: t z`

Z: z y

Y: y => im

X: re+i·im re

L: ? re+i·im

The code has not seen much testing, so please try it, see what you get and report any errors and problems here.

Edit: added a few steps to make the routine also work for 0+0i.

Dieter

01-27-2019, 03:47 AM

(01-26-2019 04:23 PM)Dieter Wrote: [ -> ](01-26-2019 01:04 PM)rprosperi Wrote: [ -> ]...if you look closely you'll see these routines preserve the stack (incl LastX) and flags...

Yes for the stack and flags, but No regarding LastX. Which is not preserved – on exit it contains a complex number or a vector, respectively.

Well, that should teach me! I read a post claiming all was preserved and while I bothered to check the flags (by reading code) and the stack contents (by testing), and all was confirmed, I did not check the LastX and extrapolated it too was safe. Never, ever assume...

Thanks for this alternate version Dieter. For the 2nd time in a week, after not touching it for a couple years, I've decided to enter programs in my 35S. If I learned about how useful and well-behaved equations are on the 35S when I got mine in 2007, I've totally forgotten it, so Pauli and your programs are good examples of how this feature can be used to build well-behaved functions pretty easily.

01-27-2019, 08:26 AM

For complex decomposition, returns real part to stack level X & imaginary to variable I:

Code:

`1 LBL A`

2 STO I

3 R↓

4 ABS(I)*COS(ARG(I))+0*(ABS(I)*SIN(ARG(I))►I)

5 RTN

01-27-2019, 09:14 AM

(01-27-2019 08:26 AM)Gerald H Wrote: [ -> ]Code:

`4 ABS(I)*COS(ARG(I))+0*(ABS(I)*SIN(ARG(I))►I)`

That's a nice approach, with a much less complicated formula than the one I used. Combining it with my original solution the result would look like this:

Code:

`C001 LBL C`

C002 FS? 10

C003 GTO C010

C004: ARG

C005 eqn ABS(LASTX)*SIN(REGX)

C006 X<>Y

C007 R↓

C008 eqn ABS(LASTX)*COS(REGT)

C009 RTN

C010: CF 10

C011 XEQ C004

C012 SF 10

C013 RTN

Maybe this version is a bit more prone to roundoff errors so that the last digit may be slightly off here and there:

1i1 => 0,99999999998, 0,999999999997

-4i3 => -3,99999999999, 3,00000000001

0i3 => 1,4689...E-11, 3

The last example assumes radians mode.

OK, this may happen anytime as all we got are 12 digits instead of 15 the 35s uses internally. But on average the more complicated formulas in post #10 seem to exibit less of such problems. In all three cases it returns accurate results. Maybe because sine and cosine of the angle are avoided (only their sign is considered).

Dieter

HP Forums > HP Calculators (and very old HP Computers) > General Forum > Best Pol/Rect and Complex Number Decomp for 35S

**HP Forums:**https://www.hpmuseum.org/forum/index.php**:**

Powered By MyBB, © 2002-2021 MyBB Group