Thread Closed 
Reading one or two arguments
03-14-2021, 11:54 AM (This post was last modified: 03-14-2021 03:11 PM by essen.)
Post: #6
RE: Reading one or two arguments
(03-13-2021 04:18 PM)HillyBoy Wrote:  Hi,

This is my first post on this forum. I have been using a HP-48GX for some 30 years now, but that died on me a few days ago. I replaced it with a HP-Prime and try to understand the current PPL language.

On my 48GX I had a small program that allowed me to convert a vector to its two arguments and vice versa. These vectors I use a lot in land-surveying: by switching from and to polar mode I can easily convert a coordinate-pair to distance and argument and vice versa (and add sets to each other). On the Prime I can do the same using a complex in the following notation: (a,b).

Starting point is one or two arguments on the stack.
The problem I now have is that after testing the first argument on the stack I need to make a decision:
IF TYPE(Arg1) == 0... I need to read to read Arg2 and return them as complex (Arg1, Arg2)
IF TYPE(Arg1) == 3... there is only one complex argument available, all I need to do is return its length and argument to the stack.

Reading two arguments is easy, provided they are available:
EXPORT MyProg(Arg1, Arg2)

But as I do not know in advance whether I can get 1 or 2 arguments, I need to start my program as

EXPORT MyProg(Arg1)

and test Arg1 first, before reading Arg2 when TYPE(Arg1)==0.

The other problem I have is how to return two arguments to the stack...

thanks in advance for your suggestions,
Nicolàs

I read your objective as you wants to read the args standing on the
calculator window from your program. This is possible with the Ans(N).
Both in calculator settings - either in RPL or Algebraic mode. It is the
CAS mode, it doesn't function. But you can not have them as arguments
to your program. That is:
ThisPrg(Ans(1),Ans(2)) //This is not allowed
BEGIN
...
END;
Above not allowed

But you can do:
ThisPrg()
BEGIN
LOCAL a1,a2;
a1:=Ans(1);
a2:=Ans(2);
//now do operations on a1 and a2 and return the result to the window.
END;

Try below with your calculator in Algebraic mode setting and in HOME mode:
Put this on the window in same order as here. You will get arg and modulus
displayed in the window ( polar coor):
5.7735026919
10.0

and run MyPrg() from the command line:

MyPrg()
BEGIN
LOCAL a1,a2, r1,ang1,plar;
a1:=Ans(1);
a2:=Ans(2);
r1:=(a1^2+a2^2)^0.5;
Z1:=(a1,a2); //the complex
ang1:=ARG(Z1);
plar:=polar_coordinates(Z1);
//RETURN(plar);
RETURN(EXPR("["+r1+,","+ang1+"]")); //calc. by you own
END;

Of course, you can have args in MyPrg(), but just not Ans(N),
but inside as shown is OK.

I have an addition. You should be aware of this:

When using the ARG() function with the calculator in CAS mode
(in this case you don't, as Ans() does not function in this mode).
But in other programs in possibly CAS mode running, the angles
will always come out in radians, even the angle mode are set to
degrees in both HOME and CAS.

Therefore, if you calculates angles in CAS modes and want the result
out in degrees, then use the angle() function. See the help how that
one function.:

It uses 3 points angle((a1,b1),(a2,b2),(a3,b3)). It measure both
the angle and its direction as well as the quadrant its laying in.
Measuring an angle in a normal right angled (x,y) coordinate-system,
the first 2 points should always be set the same as (0,1, ...), because,
0 stands for the coordinate-systems origon (0,0), and the second
point 1 stands for the point laying on the x-axes (1,0).
Shorthand notations for these 2 first points are being accepted.
The angle are measured like this -
You're standing on the x-axes in point (1,0), then you go to the origon
point (0,0), and then to point (a3,b3). Your traces and its directions
define the angle.
Find all posts by this user
Thread Closed 


Messages In This Thread
Reading one or two arguments - HillyBoy - 03-13-2021, 04:18 PM
RE: Reading one or two arguments - essen - 03-13-2021, 08:40 PM
RE: Reading one or two arguments - Han - 03-14-2021, 05:20 AM
RE: Reading one or two arguments - essen - 03-14-2021 11:54 AM
RE: Reading one or two arguments - essen - 03-14-2021, 10:08 PM
RE: Reading one or two arguments - essen - 03-15-2021, 12:27 PM
RE: Reading one or two arguments - essen - 03-16-2021, 09:00 PM
RE: Reading one or two arguments - Gene - 03-17-2021, 08:55 PM



User(s) browsing this thread: 1 Guest(s)