The Museum of HP Calculators

HP Forum Archive 17

[ Return to Index | Top of Index ]

Some fun during lunch
Message #1 Posted by Miguel Toro on 27 July 2007, 7:15 p.m.

Reading complains about the 35s unable to separate real and imaginary parts from a complex number, I made these little and unambitious programs to "help" get them apart and to try some of the new features.

Usage:
1.- execute the program
2.- Enter complex number as xiy - R/S
    --> now you see the number in polar mode
3.- Enter angle  - R/S
    --> you see the number in polar mode again
4.- Enter radius - R/S
    --> you get both x and y separated.

With programs A and B, they are in the X and Y registers, with program C you get a vector.

     
Program A

A001 LBL A A002 STOP A003 r@a (polar mode) A004 STOP A005 x<>y A006 STOP A007 REGZ A008 SIN A009 x<>y A010 * A011 LASTx A012 REGT A013 COS A014 * A015 xiy (rectangular mode) A016 RTN

LN=56

Program B

B001 LBL B B002 STOP B003 r@a B004 STOP B005 x<>y B006 STOP B007 ENTER B008 REGY * SIN(REGT) B009 REGY * COS(REGT) B010 xiy B011 RTN

LN=61

Program C

C001 LBL C C002 STOP C003 r@a C004 STOP C005 x<>y C006 STOP C007 [REGX*COS(REGZ),REGX*SIN(REGZ)] C008 xiy C009 RTN

LN=58

note: I am having fun like a little kid :-)

Well, pure RPN is smaller and faster (but speed does not really matters here) and this could be just the spark for someone to write a "real" converter.

Regards,

Miguel

      
P->R and R->P on the HP35s
Message #2 Posted by Reth on 27 July 2007, 10:10 p.m.,
in response to message #1 by Miguel Toro

Well this is my first attempt to deal with that problem :) I'm waiting for a real converter too

My program label S is dedicated for subroutines and here are the first ones:

S001     LBL S 
S002     GTO S004 
S003     GTO S015 
S004     X<>Y 
S005     SIN 
S006     X<>Y 
S007     LASTx 
S008     COS 
S009     X<>Y 
S010     * 
S011     X<>Y 
S012     LASTx 
S013     * 
S014     RTN 
S015     i 
S016     * 
S017     + 
S018     ABS 
S019     LASTx 
S020     ARG 
S021     360       ; optional, to get angles between 0 and 360 
S022     RMDR      ; optional, to get angles between 0 and 360 
S023     X<>Y 
S024     RTN 
If not obvious, XEQ S002 is equivalent of theta,r -> x,y on the HP-33s and XEQ S003 - of x,y -> theta,r

Cheers, Reth

            
Re: P->R and R->P on the HP35s
Message #3 Posted by Les Wright on 28 July 2007, 12:43 a.m.,
in response to message #2 by Reth

Reth, I think your steps S002 and S003 are redundant.

Take those out, and everything moves up two lines. One can call the polar->rect conversion with XEQ S001, or simply XEQ S ENTER, and the other conversion with XEQ S013.

This may even speed things up very slightly.

Les

                  
Re: P->R and R->P on the HP35s
Message #4 Posted by Reth on 28 July 2007, 1:40 a.m.,
in response to message #3 by Les Wright

Sure Les, even XEQ S002 would do for the P->R routine reducing steps by 1 ;). I'm just trying to create permanent addresses for frequently used routines as list grows up for the expense of a few more bytes. thanks and best regards, reth

      
Re: Some fun during lunch
Message #5 Posted by Les Wright on 28 July 2007, 12:37 a.m.,
in response to message #1 by Miguel Toro

Miguel, I think that everyone here with a 35s is eventually going to need a short fast subroutine that returns the Re and Im parts of complex number. I have come up with one that does it in 14 or so steps, but I don't want to put it here yet because I really believe it can and should be briefer and faster. Fortunately, taking Re and Im components from the stack to create a complex number is much easier to program--a program with the equation REGY + i*REGX is just one way to do it.

One thing I do like--one has a choice of how one enters complex numbers on the 35S irrespective of whether one is in xiy or r@a mode, since both the i and @ keys are right there to choose from. Even on the 42s, the behaviour of a ENTER b COMPLEX is contingent on angle mode and whether one has set RECT or POLAR. I sometimes find this a nuisance.

I don't like ALG mode so I can't comment on x+iy mode with much intelligence.

Any takers out there regarding the smallest and fastest subroutine that returns the Re and Im parts of a complex number?

Les

Edited: 28 July 2007, 12:38 a.m.

            
Re: Some fun during lunch
Message #6 Posted by Les Wright on 28 July 2007, 4:39 a.m.,
in response to message #5 by Les Wright

Hi there, this is the shortest I have been able to come up with (at least the shortest in strict RPN). I would like to know if there are shorter and faster ways of decomposing a complex number to Re and Im parts

LBL I
ENTER
ABS
X<>Y
ARG
SIN
LASTx
COS
REGZ
*
X<>Y
REGZ
*
RTN

Works simply. Place xiy (or the equivalent r@a) on the stack. XEQ I ENTER. And you get x in the Y register and y in the X register, just as though one executed COMPLEX on a complex number in rectangular mode on the 42S.

There is an annoying vulnerability to occasional rounding error. For example when executing the routine on 5i13, I get 5.00000000001 for the real part. If there is a work around for this I would be grateful. I want to blame the cosine bug, but since Arg(5i13) is approximately 70 degrees, and nowhere near the troublesome range between 89 and 90 degrees, I don't think it is the culprit in this example.

Les

Edited: 28 July 2007, 5:07 a.m.

                  
Re: Some fun during lunch
Message #7 Posted by Reth on 28 July 2007, 5:18 a.m.,
in response to message #6 by Les Wright

Hi Les, that's shorter ;)

LBL I
ABS
LASTx
ARG
SIN
LASTx
COS
REGZ
*
X<>Y
REGZ
*
RTN

that's shorter too and doesn't depend on flag 10 :)

LBL I ABS LASTx ARG SIN LASTx COS ENTER R^ * R^ R^ * RTN

to get rid of that 5.00000000001 I'd set the HP35s to say FIX 9 and then do RND after multiplications and finish with ALL

Cheers, Reth

                  
Re: Some fun during lunch
Message #8 Posted by Miguel Toro on 28 July 2007, 5:37 a.m.,
in response to message #6 by Les Wright

Les,

You do not really need the first ENTER. Here:

I001 LBL I
I002 ABS
I003 LASTx
I004 ARG
I005 SIN
I006 LASTx
I007 COS
I008 REGZ
I009 *
I010 x<>y
I011 REGZ
I012 *
I013 RTN

Just one step shorter.

Miguel

Done!

Edited: 28 July 2007, 10:06 a.m. after one or more responses were posted

                        
Re: Some fun during lunch
Message #9 Posted by Les Wright on 28 July 2007, 6:10 a.m.,
in response to message #8 by Miguel Toro

Take out what you have called step I005 and correct the numbering and I think it is right. Les

      
Re: Some fun during lunch
Message #10 Posted by Ren on 31 July 2007, 11:14 a.m.,
in response to message #1 by Miguel Toro

20070731

Hmmm, I am a loooonnnngggg way from considering programming a calculator a "fun lunch" activity!

I guess that is why I'm only ranked "Geek, 3rd Class (G3C)"

B^)

Ren

dona nobis pacem

P.S. keep up the good work!

            
Re: Some fun during lunch
Message #11 Posted by Miguel Toro on 31 July 2007, 1:05 p.m.,
in response to message #10 by Ren

Please,

Do not call me geek in from of my children (Irene, the older, has read this message while I was looking at it): they still think that I am cool. ;-)

Miguel

                  
Re: Some fun during lunch
Message #12 Posted by Les Wright on 1 Aug 2007, 11:57 p.m.,
in response to message #11 by Miguel Toro

Geek is the new cool.

Haven't you heard? ;)


[ Return to Index | Top of Index ]

Go back to the main exhibit hall