The Museum of HP Calculators

HP Forum Archive 17

[ Return to Index | Top of Index ]

Program format from 33s to 35s
Message #1 Posted by romeo_charlie on 15 Sept 2007, 2:14 p.m.

Hello all.

I am new to this forum. I've been reading the posts for a ehile, and decided to go ahead and post my question. I am hoping to get some help from some of the experts whose messages I have been reaing recently.

I used the program from Dave Coffin for the HP-33s for distance and bearing calculation. Now, I have just bought a 35s, and have found that the polar to rectangular conversion just doesnt work the same way. Unfortunately, I am just an airline pilot, and am no computer or math expert.

I was hoping that someone could help me modify this program to make it work in the HP-35s, since replacing the critical lines (D08, D13, D16, D20, D25) by the routines I read about yesterday in this site dont make it work.

Here's the Dave Coffin program:

D01 LBL D
D02 DEG
D03 INPUT N
D04 STO X
D05 INPUT E
D06 INPUT N
D07 1
D08 (polar to rectangular)
D09 INPUT E
D10 R up
D11 -
D12 x<>y
D13 (polar to rectangular)
D14 R up
D15 x<>y
D16 (rectangular to polar)
D17 x<>y
D18 RCL- X
D19 x<>y
D20 (polar to rectangular)
D21 180
D22 Rdown
D23 Rdown
D24 +/-
D25 (rectangular to polar)
D26 Rdown
D27 -
D28 x<>y
D29 ACOS
D30 60
D31 ×
D32 RTN

You enter initial Latitude and Longitude and Final Latitude and Longitude, and it returns the distance in nautical miles and true departure course to fly the great circle trajectory.

I hope I am not bothering the audience with my ignorance about HP calculators.

Thanks in advance for any help.

Rafael.

Edited for grammar.

Edited: 15 Sept 2007, 2:39 p.m.

      
Re: Program format from 33s to 35s
Message #2 Posted by Karl Schneider on 15 Sept 2007, 6:31 p.m.,
in response to message #1 by romeo_charlie

Welcome, Rafael!

Quote:
Unfortunately, I am just an airline pilot, and am no computer or math expert.

Certainly no need to be humble about that...

Quote:
Now, I have just bought a 35s, and have found that the polar to rectangular conversion just doesnt work the same way (as it did in the HP-33s).

Yes, this has been source of considerable consternation in this group. I belive that it was a horrible idea.

I've also had to deal with that same issue while porting my HP-32S/32SII/33s program to the HP-35s. The basic problem is that while "Th,r->y,x" and "y,x->Th,r" utilize only two stack registers, the conversion procedures that would be employed on the HP-35s almost always require more. This might cause the program to fail, by causing stack overload.

If the program were optimized for the HP-35s, many of the conversions could be eliminated, with calculations done using complex numbers in polar mode. But that would take some effort.

Polar to rectangular:

I replaced "Th,r->y,x" with code that used all four stack registers.

(magnitude)
ENTER
ENTER
(angle value) 
ENTER
SIN
x<>y
COS
Roll_up
*             (result is x-coordinate)
Roll_down
*             (result is y-coordinate)

For two-level calculations, an alternative is to store results and inputs to lettered registers, then recall them as necessary:

(magnitude)
STO M
(angle value)
STO A
SIN
*             (result is y-coordinate)
x<> M
RCL A
COS
*             (result is x-coordinate)
RCL M         (result is y-coordinate)

Rectangular to polar:

The difficulty is that ARG (or conversion to polar representation of a complex number) is the only way to access the "atan2" function, which gives the proper quadrant of the angle -- very important in navigation.

Using complex-valued functions, with one extra stack register:

(x-coordinate)
(y-coordinate)
i
*
+
ENTER
ABS           (result is magnitude)
x<>y
ARG           (result is angle value)

To use only two stack registers will require a storage register and a bit more thought...

Quote:
I hope I am not bothering the audience with my ignorance about HP calculators.

Thanks in advance for any help.


Not at all; our pleasure.

-- KS

Edited: 15 Sept 2007, 6:50 p.m.

            
Re: Program format from 33s to 35s
Message #3 Posted by Jeff O. on 15 Sept 2007, 8:55 p.m.,
in response to message #2 by Karl Schneider

Rafael,
Like Karl says, welcome! Following up on some of Karl's points, the following routines preserve the stack and Last X and require no registers:

Rectangular to Polar
ABS		
Roll Down		
Roll Down		
Eqn LASTx+i*REGT		
ENTER		
Roll Down		
Roll Down		
Eqn ARG(REGT)		
Eqn ABS(REGT)		
RTN		

Polar to Rectangular ABS x<>y Roll Down Roll Down Eqn LASTx*SIN(REGZ) Eqn LASTx*COS(REGT) RTN

The original program you presented would appear as follows with these routines added as subroutines:

D001  LBL D
D002  DEG
D003  INPUT N
D004  STO X
D005  INPUT E
D006  INPUT N
D007  1
D008  XEQ D043   (polar to rectangular)
D009  INPUT E
D010  R up
D011  -
D012  x<>y
D013  XEQ D043   (polar to rectangular)
D014  R up
D015  x<>y
D016  XEQ D033   (rectangular to polar)
D017  x<>y
D018  RCL- X
D019  x<>y
D020  XEQ D043   (polar to rectangular)
D021  180
D022  Rdown
D023  Rdown
D024  +/-
D025  XEQ D033   (rectangular to polar)
D026  Rdown
D027  -
D028  x<>y
D029  ACOS
D030  60
D031  ×
D032  RTN
D033  ABS		
D034  Roll Down		
D035  Roll Down		
D036  Eqn LASTx+i*REGT		
D037  ENTER		
D038  Roll Down		
D039  Roll Down		
D040  Eqn ARG(REGT)		
D041  Eqn ABS(REGT)		
D042  RTN		
D043  ABS		
D044  x<>y	
D045  Roll Down		
D046  Roll Down		
D047  Eqn LASTx*SIN(REGZ)		
D048  Eqn LASTx*COS(REGT)		
D049  RTN		

Of course it would be far better if the next version of the 35s looks like this:



Edited to replace the original routines with Miguel's improved versions.

Edited: 17 Sept 2007, 10:11 a.m. after one or more responses were posted

                  
Re: Program format from 33s to 35s - for Jeff **CORRECTED**
Message #4 Posted by Miguel Toro on 15 Sept 2007, 10:01 p.m.,
in response to message #3 by Jeff O.

Hello Jeff and welcome Rafael,

Please see at this two versions for P->R and R->P, they are shorter and get the same result (they preserve the stack and LAST x), I think:

Polar to Rectangular
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
ABS
x<->y
RDN
RDN
eqn LASTx*SIN(REGZ)
eqn LASTx*COS(REGT)
RTN

Rectangular to Polar ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ABS RDN RDN eqn LASTx+i*REGT ENTER RDN RDN eqn ARG(REGT) eqn ABS(REGT) RTN

Please tell me what you think.

Regards,

Miguel

Edited: 16 Sept 2007, 9:53 a.m. after one or more responses were posted

                        
Re: Program format from 33s to 35s - for Jeff
Message #5 Posted by Reth on 16 Sept 2007, 6:02 a.m.,
in response to message #4 by Miguel Toro

Usage of ABS as first line makes both routines give wrong answer where DIST or Y-coord is negative. Also using equations implies taking into consideration status of flag 10.
Regards, Reth

Edited: 16 Sept 2007, 6:17 a.m.

                              
Re: Program format from 33s to 35s - for Jeff
Message #6 Posted by romeo_charlie on 16 Sept 2007, 7:20 a.m.,
in response to message #5 by Reth

Thanks a lot for all for your quick replies to my message.

I'll input your routines in the 25s and will perform some sample calculations. I will compare the calc returns to the correct answer and will let you know, since some have pointed out possible errors.

Stay well.

Rafael.

                                    
Re: Program format from 33s to 35s - for Jeff
Message #7 Posted by Maximilian Hohmann on 16 Sept 2007, 8:19 a.m.,
in response to message #6 by romeo_charlie

Hello colleague!

Quote:
I will compare the calc returns to the correct answer and will let you know, since some have pointed out possible errors.

I can tell you right now that you will not get any correct answer by trying to solve a spherical problem (= great circle navigation) by using a flat approach (i.e. using those built-in or homemade P/R conversions). It will work sufficiently well for very short distances only.

You need to program the correct formulae instead (look here for example: http://en.wikipedia.org/wiki/Great-circle_distance ) if you want correct results.

Anyway: Please don't tell me that you intend to navigate along great circle routes by typing co-ordinates into your pocket calculator (or that your employer allows you to do that!). Otherwise I will prefer to stay on the ground while you are up there ;-)

Happy landings, Max

                                          
Re: Program format from 33s to 35s - for Jeff
Message #8 Posted by romeo_charlie on 16 Sept 2007, 11:08 a.m.,
in response to message #7 by Maximilian Hohmann

Quote:
Hello colleague!

I can tell you right now that you will not get any correct answer by trying to solve a spherical problem (= great circle navigation) by using a flat approach (i.e. using those built-in or homemade P/R conversions). It will work sufficiently well for very short distances only.

You need to program the correct formulae instead (look here for example: http://en.wikipedia.org/wiki/Great-circle_distance ) if you want correct results.

Anyway: Please don't tell me that you intend to navigate along great circle routes by typing co-ordinates into your pocket calculator (or that your employer allows you to do that!). Otherwise I will prefer to stay on the ground while you are up there ;-)

Happy landings, Max


Max!

Nah, dont worry! I trust our two good old million-dollar Honeywell FMS's, along with our three laser gyro IRS's on board for actual navigation over the atlantic in the Airbus.

If those fail, there is a completely detailed procedure for that.

This is just a little hobby I got going, and since I already succeeded solving spherical trigonometry ecuations in the older and bigger HP-48sx for the calculation of the great circle distances and angles, I wanted to approach this problem in the smaller HP-35s.

It's spherical triangle ecuations you got me working on "as we speak", but as I said, I'm no computer expert and it's hard.

Happy landings to all,

Rafael.

                              
Re: Program format from 33s to 35s - for Jeff
Message #9 Posted by Miguel Toro on 16 Sept 2007, 9:46 a.m.,
in response to message #5 by Reth

Hi Reth,

In the P->R procedure that is prevented thanks to the use of LASTx: the original value before the ABS is there.

I corrected the R->P procedure to have the same behavior: the use of LASTx to recover the original value.

You are right about the flag 10 and that will depend on the use of these routines in Rafael's program.

Thanks,

Miguel

Edited: 16 Sept 2007, 9:57 a.m.

                        
Re: Program format from 33s to 35s - for Jeff **CORRECTED**
Message #10 Posted by Jeff O. on 16 Sept 2007, 7:45 p.m.,
in response to message #4 by Miguel Toro

Quote:
Please tell me what you think.
I think I like them better than my versions. Nice work!
      
Re: Program format from 33s to 35s
Message #11 Posted by Paul Dale on 16 Sept 2007, 5:02 p.m.,
in response to message #1 by romeo_charlie

For a long article on rectangular to polar conversions look at this discussion. By the end, the programs for doing the conversion were pretty good. I've submitted the "best" to the museum for inclusion in the software library. I've also included them here:

P001  LBL P
P002  FS? 10
P003  GTO P011
P004* Rv
P005  Rv
P006  eqn REGZ+i*REGT
P007  ARG
P008  LASTx
P009  ABS
P010  RTN
P011* CF 10
P012  XEQ P004
P013  SF 10
P014  RTN

R001 LBL R R002 FS? 10 R003 GTO R012 R004* Rv R005 Rv R006 eqn [REGZ*SIN(REGT),REGZ*COS(REGT)] R007 [1,0] R008 x<>y R009 * R010 EQN LASTx*[0,1] R011 RTN R012* CF 10 R013 XEQ R004 R014 SF 10 R015 RTN

Both routines preserve the Z and T registers and return their results in the X and Y registers. The are also independent of the settings on the calculator and honour the current trig mode.

- Pauli


[ Return to Index | Top of Index ]

Go back to the main exhibit hall