▼
Posts: 50
Threads: 19
Joined: Jan 1970
I was wondering if anyone can give me some advice on how to use one set of input data to do two caculations?
i'm writing a coordinate join program for my 48g (im not very skilled i only learnt to program a few hours ago) and i want my set of eastings and northings for 2 points to be able to calculate horizontal distance and quadrant angle, which they can already do by themselves, but i cant seem to combine them together properly into one soft key.
here is what ive come up with so far:
Hoz Distance: << > A B C D 'sqrt( (CA)^2 + (DB)^2)' >>
Quadrant Angle: << > A B C D 'ATAN( (DB) / (CA) )' >>
*where A,B,C and D are east1, north1, east2, north2, respectively
I want these two values to be either side by side such as (Dist, QA), or in different stack positions (preferrably the latter) such as:
2: 155.396
1: 59.47381164
any advice would be greatly appreciated!
cheers,
dan
▼
Posts: 35
Threads: 1
Joined: Jan 2007
Hi! I hoped I understood your issue correctly.
Actually the easiest is to merge both programs in one :
<< > A B C D << 'sqrt((CA)^2+(DB)^2)' EVAL 'ATAN((DB)/(CA))' EVAL >>
To get the 2 values on the stack.
If your prefer to have it displayed in cimplex form, you just need to add R>C after the last EVAL.
Now if you prefer keeping 2 separate programs, you can create a new one like this :
<< > A B C D << A B C D Name your program for Horizonal Distance A B C D Name your program for Quadrant Angle >>
Regards, Bruno
▼
Posts: 709
Threads: 104
Joined: Nov 2005
The HP48 series can also take an algebraic expression instead of a subprogram. For example,
<< > A 'A^2+4' >>
would also work. If you want it in complex mode (note you may need to change the system flags on how a complex number is displayed: u+vi versus (u,v))
<<
> A B C D
'( SQRT( (CA)^2 + (DB)^2 ) , ATAN( (DB)/(CA) ) )'
>>
would get the job done and return a complex number whose real part is the distance and whose imaginary part represents the angle. You can optionally add in the command C>R to convert from complex to two reals:
<<
> A B C D
'( SQRT( (CA)^2 + (DB)^2 ) , ATAN( (DB)/(CA) ) )'
C>R
>>
To add to Bruno's post, if you stored the distance program under DIST and the angle program under ANGL the you could just use the following program:
<<
4 DUPN
DIST ANGL
R>C
>>
Edited: 9 Oct 2006, 8:18 p.m.
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
Quote:
<<
> A B C D
'( SQRT( (CA)^2 + (DB)^2 ) , ATAN( (DB)/(CA) ) )'
C>R
>>
This is syntactically incorrect because you can either use an algebraic after > or a program but not an algebraic followed by some other command.
If you want a complex number where the angle is in fact an angle, try the following:
<<
> A B C D
'( SQRT( (CA)^2 + (DB)^2 ) , <) ATAN( (DB)/(CA) ) )'
>>
<) is the angle symbol (right shift space on the 48). Go to the modes screen and change the coordinate system to 'Polar', otherwise your results are displayed in rectangular coordinates. You can switch between these display modes and watch the effect on the stack.
Marcus
▼
Posts: 709
Threads: 104
Joined: Nov 2005
Quote:
This is syntactically incorrect because you can either use an algebraic after > or a program but not an algebraic followed by some other command.
Actually, it is in fact syntactically correct. One just has to keep in mind that whatever follows that algebraic object (or program) can not require the input that is used since the scope of those variables lies within the algebraic object and not anywhere outside. The > function simply allows us to embed a subroutine within a program directly. So more commands can follow if we want.
In other words,
<< > T 'T^2' 2 + >>
with input 2 would correctly return the expected result 8. However
<< > T 'T^2' T + >>
with input 2 would return unexpected results (depends on what T is).
You would get '2^2+T' if T is undefined. If T is yet another program, then that program would run, followed by the + command.
But you are right about the polar vs rectangular mode. I just realized I was in rectangular mode, so that my solution would be ok. However if one is in polar mode, then the <) is needed.
Edited: 10 Oct 2006, 5:44 p.m.
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
Han,
thanks for the clarification about the use of > and the local variable scoping.
Quote: But you are right about the polar vs rectangular mode. I just realized I was in rectangular mode, so that my solution would be ok. However if one is in polar mode, then the <) is needed
That's not quite correct. The polar/rectangular mode setting has an influence just on the display of complex numbers or vectors, not on the entry format. If you want to enter a complex number in polar coordinates, you must use the angle symbol on the second number. What my proposal actually meant was to represent a value that is actually composed of a length and a direction in the calculator as such. So no matter what the display format is, the angle symbol in the formaula always a good idea if you want to perform other operations on the value. In order to see it correctly, polar display should be set.
As a hint to Dan: Just use complex numbers or vectors for your calculation. Put two of them on the stack, add them together and choose the proper display format. You can use the functions ABS and ARG to extract the vector length and angle of the result, respectively.
Marcus
▼
Posts: 709
Threads: 104
Joined: Nov 2005
Marcus,
Ahh, now I am beginning where I was confused. I think your suggestion about using complex numbers is indeed the best, as the ABS and ARG functions save us from having to write programs for those values (and saves a few bytes of RAM, too).
Han
Posts: 709
Threads: 104
Joined: Nov 2005
Depending on your system flags, sometimes EVAL will not produce numerical results (has to do with symbolic vs numeric results). You may want to use >NUM instead, as this will always ensure that your results are numerical and not symbolic (algebraic expressioni involving the sqrt function).
Han
Posts: 50
Threads: 19
Joined: Jan 1970
thanks everyone for all your help, this is a really helpful forum here!
the EVAL worked just fine, but i will certainly play around with all the other suggestions to learn some more about RPL.
thanks again ;)
Posts: 28
Threads: 6
Joined: Feb 2006
it is my join program, wish it can give you some hints,
since coordinate join program is "vector program",not"scalar program"
example : atan(1/1)=45 , atan(1/1)=45
and you also calculate sqrt[(1)^2+(1)^2]=1.4142
one pair value > two calculation > two answer
if you use other hp RPN calculator, you will find that
1 enter 1 >P
you can get 1.4142(dist),45 (Az from north)
1 enter 1 >P
you can get 1.4142(dist),135 (Az from north)
I think that you know the different 45 and 135
one pair value > one calculation > one pair answer
if you use atan you need write test the subroutine , my program does not need test and also solve negative angle eg.45=315
<< RECT * set calculator to rectangular mode
<< STN.N N 
>> EVAL * calculator delta N
<< STN.E E 
>> EVAL * calculator delta E
>V2 CYLIN >V ** change the pair value to polar mode
<< 180 +
>> EVAL
>HMS *change DDD.DDDD to DDD.MMSS
'AZ' STO
'HD' STO
'AZ' RCL "AZ=" >TAG
'HD' RCL "HD=" >TAG
>>
** you can refer the vector function from you manual
