The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

More programs for polar-rectangular conversion on HP Prime
Message #1 Posted by Michael de Estrada on 1 Nov 2013, 8:47 p.m.

There have been several approaches discussed on this topic, but I wanted something that would most closely approach the on-key method used on the older calculators such as the HP 33s, where you enter the two values and the result is shown directly on the screen. The best way IMO is to create the output result as a complex number pair. The programs are as follows:

EXPORT Rect_to_Polar(X1,X2)
BEGIN
LOCAL CRP,CIP,CTOT;
CRP:=(X1^2+X2^2)^.5;
CIP:=ATAN(X2/X1);
CTOT:=(CRP,CIP);
RETURN CTOT;
END;

EXPORT Polar_to_Rect(X1,X2)
BEGIN
LOCAL CRP,CIP,CTOT;
CRP:=X1*COS(X2);
CIP:=X1*SIN(X2);
CTOT:=(CRP,CIP);
RETURN CTOT;
END;

To execute from either the Home or CAS screen, select the program from the Toolbox User menu, and enter the values. For example, to convert X=3 and Y=4 in rectangular form to polar, execute Rect_to_Polar as follows:

Rect_to_Polar(3,4) Enter ---> (5.0000,53.1301)

This is assuming complex numbers displayed as (a,b), angular mode in degrees and number format set as Fixed 4.

      
Re: More programs for polar-rectangular conversion on HP Prime
Message #2 Posted by Joe Horn on 2 Nov 2013, 8:01 a.m.,
in response to message #1 by Michael de Estrada

You want to enter a complex pair, then display the polar equivalent onscreen with just a few keystrokes? Would one shifted keystroke be ok?

In Home Degree mode, type (3,4) and press Enter, then press Shift multiply (looks like an angle symbol):

You can convert the other direction too, if you use the angle symbol instead of a comma as you type in the ordered pair.

The drawback of this method is that it only works in Home, not CAS.

            
Re: More programs for polar-rectangular conversion on HP Prime
Message #3 Posted by Michael de Estrada on 2 Nov 2013, 10:14 a.m.,
in response to message #2 by Joe Horn

Thanks, Joe. I was already aware of the keyboard entry from Tim W's earlier post, but just wanted to do it as a general program that worked everywhere. Also, FYI, you can do the polar-to-rectangular conversion in CAS by entering the complex number in polar form, and it will automatically convert it to rectangular form.

                  
Re: More programs for polar-rectangular conversion on HP Prime
Message #4 Posted by Marcus von Cube, Germany on 2 Nov 2013, 1:57 p.m.,
in response to message #3 by Michael de Estrada

As an aside, angular mode can be toggled by a tap on the top right corner of the screen. This opens a small window where you can tap on either angle mode symbol.

      
Re: More programs for polar-rectangular conversion on HP Prime
Message #5 Posted by Michael de Estrada on 4 Nov 2013, 12:43 a.m.,
in response to message #1 by Michael de Estrada

After perusing the built-in Catalog of functions, I came across functions named polar_coordinates and rectangular_coordinates that do the same thing as my programs, except that the output is presented as a 1x2 vector rather than a complex number pair. The combined program for the User Function Catalog becomes:

PR_Convert

EXPORT Rect_to_Polar(X1,X2)
BEGIN
RETURN polar_coordinates(X1,X2);
END;
EXPORT Polar_to_Rect(X1,X2)
BEGIN
RETURN rectangular_coordinates(X1,X2);
END;


[ Return to Index | Top of Index ]

Go back to the main exhibit hall