▼
Posts: 875
Threads: 37
Joined: Jul 2005
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(X^{2}+Y^{2});
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 temptinglooking 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.
▼
Posts: 1,665
Threads: 142
Joined: Jan 2009
As Tim W pointed out to me, there's really no need to write a polartorectangular 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) > (5<angle>53.13) assuming angle mode is degrees.
▼
Posts: 1,665
Threads: 142
Joined: Jan 2009
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;
Posts: 875
Threads: 37
Joined: Jul 2005
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 stack2). Perhaps wanting to treat two reals in stack1 and stack2 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
▼
Posts: 1,665
Threads: 142
Joined: Jan 2009
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,<theta>, i.e.
X:=X1*COS(X2)
Y:=X1*SIN(X2)
R:=sqrt(X1^2+X2^2)
<theta>:=ATAN(X2/X1)
Edited: 31 Oct 2013, 3:29 a.m.
▼
Posts: 875
Threads: 37
Joined: Jul 2005
Posts: 193
Threads: 10
Joined: Mar 2008
hello,
how about
EXPORT ANG(X,Y)
BEGIN
RETURN arg((X,Y));
END;
EXPORT MAG(X,Y)
BEGIN
RETURN abs((X,Y));
END;
▼
Posts: 875
Threads: 37
Joined: Jul 2005
