HP 48G coordinate join program
#1

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( (C-A)^2 + (D-B)^2)' >>

Quadrant Angle: << -> A B C D 'ATAN( (D-B) / (C-A) )' >>

*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

#2

Hi! I hoped I understood your issue correctly.

Actually the easiest is to merge both programs in one :

<< -> A B C D << 'sqrt((C-A)^2+(D-B)^2)' EVAL 'ATAN((D-B)/(C-A))' 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

#3

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( (C-A)^2 + (D-B)^2 ) , ATAN( (D-B)/(C-A) ) )'
>>

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( (C-A)^2 + (D-B)^2 ) , ATAN( (D-B)/(C-A) ) )'
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.

#4

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

#5

Quote:
<< 
-> A B C D
'( SQRT( (C-A)^2 + (D-B)^2 ) , ATAN( (D-B)/(C-A) ) )'
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( (C-A)^2 + (D-B)^2 ) , <) ATAN( (D-B)/(C-A) ) )'
>>
<) 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

#6

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 ;)

#7

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

#8

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.

#9

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

#10

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



Possibly Related Threads…
Thread Author Replies Views Last Post
  HP Prime: run a program in another program Davi Ribeiro de Oliveira 6 2,736 11-11-2013, 08:28 PM
Last Post: Davi Ribeiro de Oliveira
  Riemann's Zeta Function update (HP-28S, HP-48G/GX/G+, HP-49G/G+/50g) Gerson W. Barbosa 0 1,095 06-30-2013, 01:01 AM
Last Post: Gerson W. Barbosa
  OT: DIFFERENTIAL EQUATIONS using the HP-48G/GX Ivan Rancati 2 1,420 06-04-2013, 04:11 AM
Last Post: Frank Boehm (Germany)
  Able to set HP 48G axis tick marks at integers? Randal B 1 1,105 01-24-2013, 12:40 AM
Last Post: Chris Dreher
  HP 48G -- entering more than one equation into the PLOT application Randal B 1 1,113 01-24-2013, 12:25 AM
Last Post: Chris Dreher
  HP 48G series -> 20 years NACHO 0 962 12-13-2012, 09:40 AM
Last Post: Nacho
  ROOT bug? HP 48S/48G Eddie W. Shore 8 3,986 07-13-2012, 07:05 PM
Last Post: Eddie W. Shore
  RPL prog for Fibonacci on HP 48G needs minor modification. help. wildpig 68 17,173 07-09-2012, 09:38 AM
Last Post: Gilles Carpentier
  HP-48G not responding Walt 3 1,629 05-20-2012, 08:03 PM
Last Post: Allen
  12c Users Invited to Join HP and Dennis Harms for Dinner tonight in San Francisco Laura (San Diego) 3 1,379 09-02-2011, 09:06 AM
Last Post: Jake Schwartz

Forum Jump: