Some fun during lunch



#2

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


#3

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


#4

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


#5

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

#6

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.


#7

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.


#8

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

#9

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


#10

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

#11

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!


#12

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


#13

Geek is the new cool.

Haven't you heard? ;)


Possibly Related Threads...
Thread Author Replies Views Last Post
  Fun graphs on HP Prime Mic 9 565 09-15-2013, 08:30 AM
Last Post: Eddie W. Shore
  Fun things found by running strings on the 39gII emulator bhtooefr 11 721 05-16-2013, 12:40 AM
Last Post: Mic
  Fun with the HP-35 Gerson W. Barbosa 11 646 08-02-2012, 10:58 AM
Last Post: Gerson W. Barbosa
  First post here: something fun... Jeff Dinkins 4 347 04-22-2012, 02:42 PM
Last Post: Jeroen Van Nieuwenhove
  devolution of the wp34s label---or fun with colors troy 19 1,364 02-09-2012, 02:52 PM
Last Post: Egan Ford
  HP 15c searchable Adv Fun Handbook (link) - done by Joe Horn Gene Wright 19 965 11-24-2011, 04:59 AM
Last Post: Joel Setton (France)
  15C LE -- fun with the PSE Katie Wasserman 6 399 09-14-2011, 04:04 PM
Last Post: Katie Wasserman
  TI people have more fun Don Shepherd 7 455 06-14-2011, 10:45 PM
Last Post: Gerson W. Barbosa
  having fun with the HP-17b Don Shepherd 12 683 06-08-2011, 10:08 PM
Last Post: Don Shepherd
  Free42 extended "SHOW" fun Glen Sanft 14 720 02-25-2011, 07:34 AM
Last Post: Gerson W. Barbosa

Forum Jump: