Rectangular to Polar, Polar to Rectangular – One more time



#2

I realize that Marcus' post regarding returning multiple values to the stack was probably more proof-of-concept than implementation of a useful rectangular to polar conversion function, but I was intrigued, so I pursued it. My first thought was that Marcus’ program did the conversion assuming the imaginary component in stack-1 and the real component in stack-2, while I prefer to assume real in stack-1 and Imaginary in stack-2. Changing Marcus’ program to do that would be easy to do if SWAP were a command, but as discussed in Marcus’ thread, it is not. Using commands that appear to be available, I came up with the following (I used reserved complex variable Z1 instead of temp):

Rectangular to Polar:

EXPORT RtoP;
KEY K_Mul()
BEGIN
"i * + i / CONJ 'Z1' |> ARG Z1 ABS"
END;

Dividing by i and then taking the conjugate swaps the components in the complex number. This seemed to work, so then I turned my attention to Polar to Rectangular conversion, with the magnitude assumed in stack-1 and the angle in stack-2. I figured I’d need two real variables, so I used reserved X and Y. Here is how I did it:

Polar to Rectangular:

EXPORT PtoR;
KEY K_Div()
BEGIN
" 'X' |> X - + 'Y' |> SIN X * Y COS X * "
END;

The “'X' |>” stores the magnitude in X, then to get the angle from stack-2, I recalled the magnitude, subtracted from itself to get zero, then added zero to the angle to drop it to stack-1. Then I could store it in Y and proceed with multiplying the magnitude by the SIN and COS of the angle. Kind of clunky, but it seems to work.

To recap the usage, for rectangular to polar, with the imaginary component in stack-2 and the real component in stack-1, press shift-help (User), then x (multiply). This puts the command string in the command line, then press ENTER and the angle will be returned to stack-2 with the magnitude in stack-1. So it takes four keystrokes to convert from rectangular to polar. This compares to 12 keystrokes for the conversion using my separate MA and AN programs. (Alpha Alpha M A Enter shift + Alpha Alpha A N Enter)

For Polar to rectangular, with the angle in stack-2 and the magnitude in stack-1, press shift-help (User), then / (divide). This puts the command string in the command line, then press ENTER and the imaginary will be returned to stack-2 with the real in stack-1. Again, four keystrokes compared to 12 for conversion using separate IG and RL programs. (Alpha Alpha I G Enter shift + Alpha Alpha R L Enter)

Again, the above is mostly proof-of-concept, done primarily to see if it could be done, like climbing Mt. Everest (with a much, much lower chance of dying in the process.)


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP 35s polar/rectangular conversion CD Dodds 6 328 11-28-2013, 02:39 PM
Last Post: Dieter
  [HP Prime]How to get Discrete-Time Fourier Transform uklo 0 241 11-18-2013, 08:02 PM
Last Post: uklo
  More programs for polar-rectangular conversion on HP Prime Michael de Estrada 4 279 11-04-2013, 12:43 AM
Last Post: Michael de Estrada
  Date/time formats R. Pienne 4 326 11-01-2013, 12:43 PM
Last Post: Marcus von Cube, Germany
  How to set the Date.Time etc on a WP34S Harold A Climer 4 324 10-29-2013, 09:32 PM
Last Post: FORTIN Pascal
  Prime: Exam mode (possible duplicate after funny response first time) Paul Townsend (UK) 1 186 10-24-2013, 03:09 PM
Last Post: Tim Wessman
  Date/time programs for the HP 35s R. Pienne 0 148 10-03-2013, 02:37 PM
Last Post: R. Pienne
  OT--Hyperbolic Polar<-->Rectangular Coordinates Matt Agajanian 2 156 09-30-2013, 08:53 PM
Last Post: Matt Agajanian
  Nothing like passing the time away... Eddie W. Shore 2 178 03-21-2013, 08:23 AM
Last Post: Eddie W. Shore
  New compile-time options for WP-34S Nigel J Dowrick 15 654 01-29-2013, 03:25 PM
Last Post: Stephan

Forum Jump: