My 2nd and 3rd Prime Programs Jeff O. Unregistered Posts: 875 Threads: 37 Joined: Jul 2005 10-30-2013, 04:10 PM Perhaps pending more discussion in my "My First Prime Program" thread, it appears that for the time being, I will need two programs for Polar conversions: ```EXPORT ANG(X,Y) BEGIN RETURN ATAN(X/Y); END; ``` And: ```EXPORT MAG(X,Y) BEGIN RETURN SQROOT(X2+Y2); END; ``` The angle routine will require some work to get things in the right quadrant for all inputs, of course. With the above, converting 3 + i4 (represented as 4 in level 2 and 3 in level 1 of the stack) to polar form requires the following: ```4 ENTER 3 ENTER ANG ENTER Ans MAG ENTER ``` Is there any way to assign the ANG and MAG programs to two of those tempting-looking blank soft keys at the bottom of the HOME screen? I promise this won't be series where I publish every trivial thing I figure out how to do. Edited: 30 Oct 2013, 4:15 p.m. Michael de Estrada Unregistered Posts: 1,665 Threads: 142 Joined: Jan 2009 10-30-2013, 04:35 PM As Tim W pointed out to me, there's really no need to write a polar-to-rectangular program, since the conversions can be done from the keyboard using complex numbers. 1) In home settings set complex number format to (a,b) and check the box for "Allow complex output from real input". 2) Enter the rectangular coordinates x,y as (x,y) into the stack/history. 3) Key in Shift x (angle symbol) to transform the coordinate to polar form (magnitude,angle). 4) Repeat Shift x to return to rectangular form. For example (3,4) ---> (553.13) assuming angle mode is degrees. Michael de Estrada Unregistered Posts: 1,665 Threads: 142 Joined: Jan 2009 10-30-2013, 04:53 PM Also, FWIW, I wrote a program to do this before Tim W chimed in as follows: ```EXPORT PR_Convert() BEGIN LOCAL X1,X2; CHOOSE(N,"PR_Convert","Polar","Rectangular"); CASE IF N==1 THEN INPUT({X1,X2},"To Polar",{"X =","Y ="},{"Enter X","Enter Y"},{0,0}); PRINT("R = " + sqrt(X1²+X2²) ); PRINT("angle = " + ATAN(X2/X1) ); END; IF N==2 THEN INPUT({X1,X2},"To Rectangular",{"R =","angle ="},{"Enter R","Enter angle"},{0,0}); PRINT("X = " + X1*COS(X2) ); PRINT("Y = " + X1*SIN(X2) ); END; DEFAULT END; END; ``` Jeff O. Unregistered Posts: 875 Threads: 37 Joined: Jul 2005 10-30-2013, 09:32 PM Hi Michael, I was aware of that functionality. In fact, the Prime's input, display, and general handling of complex numbers is pretty darn close to my ideal. You can enter either form directly from the keyboard, they stay in whatever form you enter them unless you convert as you described, and functions operating on two values in different forms produce consistent results (always in the form of the value in stack-2). Perhaps wanting to treat two reals in stack-1 and stack-2 as a complex number is anachronistic, but so am I. The 35s was raked over the coals for not having polar and rectangular conversion functions, despite having the ability to simply enter and work with complex values in a single register. In the end, I probably don't need the functions, but it would be nice if they could be programmed. Regarding your PR_convert program, rest assured that I tried it. It works great, but as I indicated in my first post, I'd like to be able to take the values from the stack and return the results to the stack. As far as I can tell, there is no way for me to grab the results from your program for use in a subsequent calculation, is there? edited for typos Edited: 31 Oct 2013, 7:40 a.m. after one or more responses were posted cyrille de Brébisson Unregistered Posts: 193 Threads: 10 Joined: Mar 2008 10-31-2013, 02:27 AM hello, how about EXPORT ANG(X,Y) BEGIN RETURN arg((X,Y)); END; EXPORT MAG(X,Y) BEGIN RETURN abs((X,Y)); END; Michael de Estrada Unregistered Posts: 1,665 Threads: 142 Joined: Jan 2009 10-31-2013, 03:28 AM Quote: As far as I can tell, there is no way for me to grab the results from your program for use in a subsequent calculation, is there? You can retrieve them by assigning them to the reserved system real variables X,Y,R,, i.e. X:=X1*COS(X2) Y:=X1*SIN(X2) R:=sqrt(X1^2+X2^2) :=ATAN(X2/X1) Edited: 31 Oct 2013, 3:29 a.m. Jeff O. Unregistered Posts: 875 Threads: 37 Joined: Jul 2005 10-31-2013, 07:39 AM Thanks, I'll try that. Jeff O. Unregistered Posts: 875 Threads: 37 Joined: Jul 2005 10-31-2013, 08:18 AM Even better! Thanks! « Next Oldest | Next Newest »

 Possibly Related Threads… Thread Author Replies Views Last Post Does the HP Prime really compiles the user programs? CompSystems 3 2,768 12-13-2013, 01:55 PM Last Post: Mike Morrow HP Prime: Lists in programs Alberto Candel 7 3,548 12-04-2013, 02:16 AM Last Post: Alberto Candel HP Prime: FLOOR, iPart , and their use in programs Alberto Candel 6 2,622 12-01-2013, 10:17 PM Last Post: Alberto Candel HP Prime: matrices in programs, in need of help Alberto Candel 9 3,251 11-26-2013, 01:33 AM Last Post: cyrille de Brébisson HP Prime: password protection for programs Davi Ribeiro de Oliveira 2 1,595 11-22-2013, 12:45 PM Last Post: Geoff Quickfall Prime: Scope of Variable and functions within programs Thomas Chrapkiewicz 9 3,321 11-18-2013, 03:39 PM Last Post: Thomas Chrapkiewicz Question about transfering programs to the HP Prime Namir 10 3,476 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 2,541 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,358 11-12-2013, 11:05 AM Last Post: Joseph Ec Grouping programs on the HP Prime Michael de Estrada 11 3,751 11-04-2013, 01:38 PM Last Post: Damien

Forum Jump: