More programs for polar-rectangular conversion on HP Prime



#6

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.


#7

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.


#8

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.


#9

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.

#10

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;

Possibly Related Threads...
Thread Author Replies Views Last Post
  Does the HP Prime really compiles the user programs? CompSystems 3 2,244 12-13-2013, 01:55 PM
Last Post: Mike Morrow
  HP Prime: Lists in programs Alberto Candel 7 2,864 12-04-2013, 02:16 AM
Last Post: Alberto Candel
  HP Prime: FLOOR, iPart , and their use in programs Alberto Candel 6 2,067 12-01-2013, 10:17 PM
Last Post: Alberto Candel
  HP 35s polar/rectangular conversion CD Dodds 6 2,238 11-28-2013, 02:39 PM
Last Post: Dieter
  HP Prime: matrices in programs, in need of help Alberto Candel 9 2,581 11-26-2013, 01:33 AM
Last Post: cyrille de Brébisson
  HP Prime: password protection for programs Davi Ribeiro de Oliveira 2 1,240 11-22-2013, 12:45 PM
Last Post: Geoff Quickfall
  Prime: Scope of Variable and functions within programs Thomas Chrapkiewicz 9 2,656 11-18-2013, 03:39 PM
Last Post: Thomas Chrapkiewicz
  Question about transfering programs to the HP Prime Namir 10 2,642 11-17-2013, 04:01 PM
Last Post: Namir
  [Download] PrimeComm: Alternative small utility to upload/download programs to the HP Prime Erwin Ried 6 1,988 11-17-2013, 10:18 AM
Last Post: Erwin Ried
  HP Prime: do not send programs and shuts down by pressing Apps Davi Ribeiro de Oliveira 1 1,026 11-12-2013, 11:05 AM
Last Post: Joseph Ec

Forum Jump: