HP Forums

Full Version: Converting Polar and Rectangular
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I’m having trouble downloading a certain program for my hp prime. Every time I type in the programs below I get a syntax error. Is there anyone that has a link where I can download these programs rather than manually put them in?

P_to_R(r,a):=
BEGIN
return (r*COS(a)+r*SIN(a)*i);
END;

R_to_P(x,y):=
BEGIN
return (CAS(collect(ABS(x+y*i)))+"∡"+CAS(collect(ARG(x+y*i))));
END;
Should the programs not start with

EXPORT P_2_R(x,y)

Or something instead of your first lines?

If you try it on a calculator, it will tell you where the problem is, by clicking Info after running the program, or clicking Check, when in writing the program.
These are CAS programs, you need to add #cas and #end statements:

Code:
#cas
P_to_R(r,a):=
BEGIN
return (r*COS(a)+r*SIN(a)*i);
END;

R_to_P(x,y):=
BEGIN
return (CAS(collect(ABS(x+y*i)))+"∡"+CAS(collect(ARG(x+y*i))));
END; 
#end

Btw, you can use instead of these programs the built-in functions rectangular_coordinates() and polar_coordinates() as explained here.
Reference URL's