My 2nd and 3rd Prime Programs - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: My 2nd and 3rd Prime Programs (/thread-254357.html) My 2nd and 3rd Prime Programs - Jeff O. - 10-30-2013 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. Re: My 2nd and 3rd Prime Programs - Michael de Estrada - 10-30-2013 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. Re: My 2nd and 3rd Prime Programs - Michael de Estrada - 10-30-2013 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; ``` Re: My 2nd and 3rd Prime Programs - Jeff O. - 10-30-2013 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 Re: My 2nd and 3rd Prime Programs - cyrille de Brébisson - 10-31-2013 hello, how about EXPORT ANG(X,Y) BEGIN RETURN arg((X,Y)); END; EXPORT MAG(X,Y) BEGIN RETURN abs((X,Y)); END; Re: My 2nd and 3rd Prime Programs - Michael de Estrada - 10-31-2013 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. Re: My 2nd and 3rd Prime Programs - Jeff O. - 10-31-2013 Thanks, I'll try that. Re: My 2nd and 3rd Prime Programs - Jeff O. - 10-31-2013 Even better! Thanks!