hp41programs

Fix

Calculating a Fix for the HP-41


Overview
 

 1°)  Program#1
 2°)  Program#2
 3°)  Program#3
 4°)  Program#4 - a non-iterative method
 5°)  Program#5 - a non-iterative method
 

-After measuring the altitudes of  n = 2 , 3 ( or more ) stars,
  the following programs compute your geographical position: Longitude & Latitude
-The second routine is longer but faster than the first one.
-The 3rd program is even faster but works for 2 stars.
-The 4th & 5th programs solve directly the non-linear system via a quadratic equation: they are the fastest.
 

•  Longitudes are reckoned positively Eastwards from the meridian of Greenwich.
 

1°)  Program #1
 

-The longitude L and the latitude b are solutions of the non-linear system:

    sin b sin d1 + cos b cos d1 cos ( ST1 - a1 + L ) = sin h1               with              ST = mean Sidereal Time at Greenwich
    sin b sin d2 + cos b cos d2 cos ( ST2 - a2 + L ) = sin h2                                    ai = right-ascension  ,  di = declination  ,  hi = altitude
    ...................................................................................

    sin b sin dn + cos b cos dn cos ( STn - an + L ) = sin hn     ,     this system is overdetermined if there are more than 2 stars.

-To find L & b , we have to minimize the function

         f(L,b) = SUMi  [  sin b sin di + cos b cos di cos ( STi - ai + L ) - sin hi  ]2

-The program below employs the elementary - and slow - method used by "EXN2" ( cf "Extrema for the HP-41" § 3a )
 

Data Registers:     R00 = "T"                          R06 to R15: temp

                                R16 = ST1 - a1                   R20 = ST2 - a2            R24 = ST3 - a3             .......................      ST = Sidereal Time
                                R17 = Cos d1                     R21 = Cos d2              R25 = Cos d3                .......................      a  = Right-Ascension
                                R18 = Sin d1                      R22 = Sin d2                R26 = Sin d3                 .......................      d  = declination
                                R19 = Sin h1                      R23 = Sin h2                R27 = Sin h3                   .......................     h  = altitude

-When the program stops,  R01 = your longitude & R02 = your latitude  ( in degrees and decimals )

Flags:              F22  F29
Subroutines:  "MST"   Mean Sidereal Time at Greenwich  ( cf "Rising-Transit-Setting for the HP-41" )
                        "H0-H"   ( cf "Atmospheric Refraction for the HP-41" )
                        "EXN2"   ( cf "Extrema for the HP-41" , § 3a the second version, for n < 11 )

-Line 17 is a three-byte GTO 03  but it doesn't really matter because this line is executed only once.
-The append character is denoted  ~
-Line 59 LBL "T" may be replaced by another global name, provided it's the same as line 93
 
 

  01  LBL "FIX"
  02  1
  03  STO 01
  04  16.9
  05  STO 02
  06  CF 29
  07  DEG
  08  LBL 01
  09  FIX 0
  10  "DATE^TIME"
  11  ARCL 01
  12  "~?"
  13  FIX 4
  14  CF 22
  15  PROMPT
  16  FC?C 22
  17  GTO 03
  18  XEQ "MST"
  19  LASTX
  20  STO IND 02
  21  FIX 0
  22  "RA^DEC^ALT"   
  23  ARCL 01
  24  "~?"
  25  FIX 4
  26  PROMPT
  27  STO 09
  28  RCL Z
  29  HR
  30  ST- IND 02
  31  15
  32  ST* IND 02          
  33  ISG 02
  34  R^
  35  HR
  36  1
  37  P-R
  38  STO IND 02
  39  ISG 02
  40  X<>Y
  41  STO IND 02
  42  ISG 02
  43  RCL 09
  44  XEQ "H0-H"
  45  HR
  46  SIN
  47  STO IND 02
  48  ISG 01
  49  CLX
  50  RCL 02
  51  INT
  52   E3
  53  /
  54  16
  55  +
  56  STO 06                
  57  ISG 02
  58  GTO 01
  59  LBL "T"
  60  RCL 02
  61  RCL 06
  62  STO 10
  63  SIGN
  64  P-R
  65  STO 08
  66  X<>Y
  67  STO 09
  68  CLX
  69  LBL 02
  70  RCL 01
  71  RCL IND 10
  72  +
  73  COS
  74  RCL 08
  75  *
  76  ISG 10
  77  RCL IND 10         
  78  *
  79  RCL 09
  80  ISG 10
  81  RCL IND 10
  82  *
  83  +
  84  ISG 10
  85  RCL IND 10
  86  -
  87  X^2
  88  +
  89  ISG 10
  90  GTO 02
  91  RTN
  92  LBL 03
  93  "T"
  94  ASTO 00
  95  "STEP^LON^LAT"
  96  PROMPT
  97  STO 02
  98  RDN
  99  STO 01
100  CLX
101  2
102  XEQ "EXN2"
103  RCL 02
104  HMS
105  RCL 01
106  HMS
107  SF 29
108  CLA
109  CLD
110  END

 
   ( 213 bytes / SIZE 4n+16 )
 
 

      STACK        INPUTS      OUTPUTS
           Z             /         min(f)
           Y             /   latitude ( ° ' " )
           X             /  longitude ( ° ' " )

Example:     On 2006/04/04  you measure the altitude of n = 3 stars:

   at  6h00m  (UT)  alpha Lyr       ( RA = 18h37m09s  , Decl = 38°47'21" )      Altitude = 29°41'59"
   at  6h01m  (UT)  zeta UMaj      ( RA = 13h24m10s , Decl = 54°53'34" )      Altitude = 60°29'56"
   at  6h02m  (UT)  gamma UMin  ( RA = 15h20m43s , Decl = 71°48'43" )      Altitude = 42°26'03"

-SIZE 028 or greater, then:

        XEQ "FIX"              the HP-41 displays  "DATE^TIME1?"                    ( enter the different data and press R/S )

 2006.0404  ENTER^
       6.00        R/S           the HP-41 displays   "RA^DEC^ALT1?"
     18.3709  ENTER^
     38.4721  ENTER^
     29.4159    R/S           the HP-41 displays   "DATE^TIME2?"

 2006.0404  ENTER^
       6.01        R/S           the HP-41 displays   "RA^DEC^ALT2?"
     13.2410  ENTER^
     54.5334  ENTER^
     60.2956    R/S           the HP-41 displays   "DATE^TIME3?"

 2006.0404  ENTER^
       6.02        R/S           the HP-41 displays   "RA^DEC^ALT3?"
     15.2043  ENTER^
     71.4843  ENTER^
     42.2603    R/S           the HP-41 displays   "DATE^TIME4?"                  ( since we have only 3 stars, press  R/S  without any digit entry )

                      R/S           the HP-41 displays   "STEP^LON^LAT?"             ( enter a stepsize, say 4° and your estimated position, for instance  -70° , +20° )
           4       ENTER^
        -70      ENTER^
         20         R/S           the HP-41 executes "EXN2" and displays the successive f-values,  and 7mn39s later:

     >>>   your longitude = X-register =  -74°40'30"                 So, you are on the Atlantic Ocean, near the Bahamas!
     >>>   your latitude    = Y-register = +25°49'41"
                                         Z-register = fmin ~ 2.4 10 -11  = R13   this value must be a very small number.
 

-If the process seems to diverge, stop the program, GTO "FIX" ,  XEQ 03  and key in new estimated step/longitude/latitude.
-Too bad initial guesses may lead to a local minimum and a wrong position but in this case, Z-output is not very small.
-However, if n = 2, the system has 2 solutions. Therefore, measuring 3 altitudes is safer.
 

2°)  Program #2
 

-"FIX2" minimizes the function    f(L,b) = SUMi  [  sin b sin di + cos b cos di cos ( STi - ai + L ) - sin hi  ]2
  by equating to zero the partial derivatives with respect to L and b, it yields:

        SUMi  cos di sin ( STi - ai + L ) [  sin b sin di + cos b cos di cos ( STi - ai + L ) - sin hi  ] = 0
        SUMi  [ cos b sin di - sin b cos di cos ( STi - ai + L ) [  sin b sin di + cos b cos di cos ( STi - ai + L ) - sin hi  ] = 0
 
 

Data Registers:                  R00 = "T"                         R01 to R12 & R16 to R21; temp

              R13 = L                  R22 = ST1 - a1                 R26 = ST2 - a2                R30 = ST3 - a3      ..............
              R14 = cos b            R23 = Cos d1                   R27 = Cos d2                  R31 = Cos d3
              R15 = sin b             R24 = Sin d1                     R28 = Sin d2                   R32 = Sin d3
                                             R25 = Sin h1                     R29 = Sin h2                   R33 = Sin h3

-When the program stops,     R01 = your longitude & R02 = your latitude  ( in degrees and decimals )

Flags:              F22  F29
Subroutines:  "MST"   Mean Sidereal Time at Greenwich  ( cf "Rising-Transit-Setting for the HP-41" )
                        "H0-H"  ( cf "Atmospheric Refraction for the HP-41" )
                        "SXY"   2x2 non-linear systems  ( cf "Linear & Non-Linear Systems for the HP-41" )
 
 

  01  LBL "FIX2"
  02  1
  03  STO 01
  04  22.9
  05  STO 02
  06  CF 29
  07  DEG
  08  LBL 01
  09  FIX 0
  10  "DATE^TIME"
  11  ARCL 01
  12  "~?" 
  13  FIX 4
  14  CF 22
  15  PROMPT
  16  FC?C 22
  17  GTO 03
  18  XEQ "MST"
  19  LASTX
  20  STO IND 02
  21  FIX 0
  22  "RA^DEC^ALT"    
  23  ARCL 01
  24  "~?"    
  25  FIX 4
  26  PROMPT
  27  STO 03
  28  RCL Z
  29  HR
  30  ST- IND 02
  31  15
  32  ST* IND 02
  33  ISG 02
  34  R^
  35  HR
  36  1
  37  P-R
  38  STO IND 02
  39  ISG 02
  40  X<>Y
  41  STO IND 02          
  42  ISG 02
  43  RCL 03
  44  XEQ "H0-H"
  45  HR
  46  SIN
  47  STO IND 02
  48  ISG 01
  49  CLX
  50  RCL 02
  51  INT
  52   E3
  53  /
  54  22
  55  +
  56  STO 12
  57  ISG 02
  58  GTO 01
  59  LBL "T" 
  60  STO 13
  61  CLX
  62  STO 16
  63  STO 17
  64  STO 18
  65  SIGN
  66  P-R
  67  STO 14
  68  X<>Y
  69  STO 15
  70  RCL 12
  71  STO 19
  72  LBL 02
  73  RCL IND 19          
  74  RCL 13
  75  +
  76  ISG 19
  77  RCL IND 19
  78  P-R
  79  STO 20
  80  RCL 14
  81  *
  82  ISG 19
  83  RCL 15
  84  RCL IND 19
  85  STO 21
  86  *
  87  +
  88  ISG 19
  89  RCL IND 19          
  90  -
  91  *
  92  ST+ 16
  93  LATSX
  94  X^2
  95  ST+ 18
  96  LASTX
  97  RCL 14
  98  RCL 21
  99  *
100  RCL 15
101  RCL 20
102  *
103  -
104  *
105  ST+ 17
106  ISG 19
107  GTO 02
108  RCL 17
109  RCL 16
110  RTN
111  LBL 03
112  "T"
113  ASTO 00
114  "STEP^LON^LAT?"
115  PROMPT
116  STO 02
117  STO 04
118  RDN
119  STO 01
120  STO 03
121  X<>Y
122  ST+ 03
123  ST+ 04
124  XEQ "SXY"
125  RCL 18
126  X<> Z
127  HMS
128  X<>Y
129  HMS
130  SF 29
131  CLA
132  CLD
133  END

 
  ( 253 bytes / SIZE 022+4n )
 
 

      STACK        INPUTS      OUTPUTS
           Z             /         min(f)
           Y             /   latitude ( ° ' " )
           X             /  longitude ( ° ' " )

Example:     The same example as above:  On 2006/04/04,

   at  6h00m  (UT)  alpha Lyr       ( RA = 18h37m09s  , Decl = 38°47'21" )      Altitude = 29°41'59"
   at  6h01m  (UT)  zeta UMaj      ( RA = 13h24m10s , Decl = 54°53'34" )      Altitude = 60°29'56"
   at  6h02m  (UT)  gamma UMin  ( RA = 15h20m43s , Decl = 71°48'43" )      Altitude = 42°26'03"

-SIZE 034 or greater, then:

        XEQ "FIX2"              the HP-41 displays  "DATE^TIME1?"                    ( enter the different data and press R/S )

 2006.0404  ENTER^
       6.00        R/S           --------------------  "RA^DEC^ALT1?"
     18.3709  ENTER^
     38.4721  ENTER^
     29.4159    R/S           --------------------  "DATE^TIME2?"

 2006.0404  ENTER^
       6.01        R/S           -------------------   "RA^DEC^ALT2?"
     13.2410  ENTER^
     54.5334  ENTER^
     60.2956    R/S           -------------------   "DATE^TIME3?"

 2006.0404  ENTER^
       6.02        R/S           -------------------   "RA^DEC^ALT3?"
     15.2043  ENTER^
     71.4843  ENTER^
     42.2603    R/S           -------------------   "DATE^TIME4?"                     ( since we have only 3 stars, press  R/S  without any digit entry )

                      R/S           -------------------   "STEP^LON^LAT?"            ( enter a stepsize - say 2° - and your estimated position, for instance  -70° , +20° )
           2      ENTER^
        -70      ENTER^
          20        R/S           the HP-41 executes "SXY" and displays the successive longitude-values, expressed in degrees and decimals
                                      ( each iteration requires about 23 seconds if n = 3 ) and eventually - execution time = 2mn40s,

     >>>   your longitude = X-register =  -74°40'30"
     >>>   your latitude    = Y-register = +25°49'41"
                                         Z-register = fmin ~ 2.3 10 -11  = R18   this number must be very small.
 

-"SXY" may stop prematurely if the jacobian = 0 ( always check Z-register or R18 )
-"SXY" tries to produce very accurate results, but here, 8 decimals are superfluous.
-So, execution time can be reduced if you modify the termination criterion in the "SXY" listing.
 

3°)  Program #3
 

-If you only measure the altitudes of 2 stars, the non-linear system has only 2 equations in 2 unknowns,
 so you can solve it directly without calculating any partial derivative.

    sin b sin d1 + cos b cos d1 cos ( ST1 - a1 + L ) = sin h1                                  ( ST = mean Sidereal Time at Greenwich  ,  hi = altitude
    sin b sin d2 + cos b cos d2 cos ( ST2 - a2 + L ) = sin h2                                     L = longitude , b = latitude , ai = right-ascension , di = declination )
 

Data Registers:     R00 = "T"           R01 to R11  are used by "SXY"

              R12 = L                  R15 = ST1 - a1                 R19 = ST2 - a2                R23 = ST3 - a3             ........................
              R13 = cos b            R16 = Cos d1                   R20 = Cos d2                  R24 = Cos d3
              R14 = sin b             R17 = Sin d1                     R21 = Sin d2                   R25 = Sin d3
                                             R18 = Sin h1                     R22 = Sin h2                   R26 = Sin h3

-When the program stops,    R01 = your longitude & R02 = your latitude    ( in degrees and decimals )

Flags:              F22  F29
Subroutines:  "MST"   Mean Sidereal Time at Greenwich  ( cf "Rising-Transit-Setting" )
                        "H0-H"  ( cf "Atmospheric Refraction" )
                        "SXY"   ( cf "Linear and non-linear systems" )
 
 

  01  LBL "FIX3"
  02  1
  03  STO 01
  04  15.9
  05  STO 02
  06  CF 29
  07  DEG
  08  LBL 01
  09  FIX 0
  10  "DATE^TIME"
  11  ARCL 01
  12  "~?"      
  13  FIX 4
  14  CF 22
  15  PROMPT
  16  FC?C 22
  17  GTO 02
  18  XEQ "MST"
  19  LASTX
  20  STO IND 02
  21  FIX 0
  22  "RA^DEC^ALT"    
  23  ARCL 01
  24  "~?"   
  25  FIX 4
  26  PROMPT
  27  STO 03
  28  RCL Z
  29  HR
  30  ST- IND 02
  31  15
  32  ST* IND 02           
  33  ISG 02
  34  R^
  35  HR
  36  1
  37  P-R
  38  STO IND 02
  39  ISG 02
  40  X<>Y
  41  STO IND 02
  42  ISG 02
  43  RCL 03
  44  XEQ "H0-H"
  45  HR
  46  SIN
  47  STO IND 02          
  48  ISG 01
  49  CLX
  50  ISG 02
  51  GTO 01
  52  LBL "T"
  53  STO 12
  54  RCL 15
  55  +
  56  COS
  57  RCL 16
  58  *
  59  RCL Y
  60  COS
  61  STO 13
  62  *
  63  X<>Y
  64  SIN
  65  STO 14
  66  RCL 17
  67  *
  68  +
  69  RCL 18
  70  -
  71  RCL 12
  72  RCL 19                  
  73  +
  74  COS
  75  RCL 13
  76  *
  77  RCL 20
  78  *
  79  RCL 14
  80  RCL 21
  81  *
  82  +
  83  RCL 22
  84  -
  85  RTN
  86  LBL 02
  87  SF 29
  88  "T"
  89  ASTO 00
  90  "STEP^LON^LAT?"
  91  PROMPT
  92  STO 02
  93  STO 04
  94  RDN
  95  STO 01
  96  STO 03
  97  X<>Y
  98  ST+ 03
  99  ST+ 04
100  XEQ "SXY"
101  X<>Y
102  HMS
103  X<>Y
104  HMS
105  CLA
106  CLD
107  END

 
   ( 210 bytes / SIZE at least 023 )
 
 

      STACK        INPUTS      OUTPUTS
           Z             /          ~ 0
           Y             /         b ( ° ' " )
           X             /         L ( ° ' " )

Example:     Again the same example:  On 2006/04/04,

   at  6h00m  (UT)  alpha Lyr       ( RA = 18h37m09s  , Decl = 38°47'21" )      Altitude = 29°41'59"
   at  6h01m  (UT)  zeta UMaj      ( RA = 13h24m10s , Decl = 54°53'34" )      Altitude = 60°29'56"
   at  6h02m  (UT)  gamma UMin  ( RA = 15h20m43s , Decl = 71°48'43" )      Altitude = 42°26'03"

-SIZE 027 ( or greater ) if you want to use the 3 stars - later - then:

        XEQ "FIX3"              the HP-41 displays  "DATE^TIME1?"                    ( enter the different data and press R/S )

 2006.0404  ENTER^
       6.00        R/S           --------------------  "RA^DEC^ALT1?"
     18.3709  ENTER^
     38.4721  ENTER^
     29.4159    R/S           --------------------  "DATE^TIME2?"

 2006.0404  ENTER^
       6.01        R/S           -------------------   "RA^DEC^ALT2?"
     13.2410  ENTER^
     54.5334  ENTER^
     60.2956    R/S           -------------------   "DATE^TIME3?"

 2006.0404  ENTER^
       6.02        R/S           -------------------   "RA^DEC^ALT3?"
     15.2043  ENTER^
     71.4843  ENTER^
     42.2603    R/S           -------------------   "DATE^TIME4?"                      ( since we have only 3 stars, press  R/S  without any digit entry )

                      R/S           -------------------   "STEP^LON^LAT?"             ( enter a stepsize, say 1° and your estimated position, again  -70° , +20° )
           1      ENTER^
        -70      ENTER^
          20        R/S           the HP-41 executes "SXY" and displays the successive longitude-approximations, expressed in degrees and decimals
                                      ( each iteration requires about 12 seconds ) and about 90 seconds later, it yields:

                 L = -74°40'31''
   RDN      b =  25°49'42''         ( RDN again gives 1 E-10 which is a very small number so the solution is OK )
 

-The data in registers R23 thru R26 have not been used but you can swap these registers with R19 thru R22
 ( 19.023004  REGSWAP )   to use the stars n°1 & 3  and key in  XEQ 02 , it yields ( with the same STEP^LON^LAT ):

                L = -74°40'29''
   RDN     b =  25°49'40''    which confirms the results above

-For a last check, swap registers R15 thru R18 & R23 thru R26  ( 15.023004  REGSWAP ) and  XEQ 02 , we get ( with the same STEP^LON^LAT ):

               L = -74°40'39''
   RDN    b =  25°49'41''

-If needed, compute the average of these values to eliminate - or at least diminish - the effects of errors in the heights, refraction ...etc...
 

4°)  Program #4
 

-Actually, the non-linear system

           sin b sin d1 + cos b cos d1 cos ( ST1 - a1 + L ) = sin h1                          (  ST = mean Sidereal Time at Greenwich  ,  hi = altitude )
           sin b sin d2 + cos b cos d2 cos ( ST2 - a2 + L ) = sin h2                         (    L = longitude , b = latitude , ai = right-ascension , di = declination )

 may be solved without any iterative method:

-Let   x = sin b    After eliminating L from these 2 equations, we find that x is one solution of the quadratic equation  A x2 + B x + C = 0

                  A = tan2 d1 + tan2 d2 + sin2 ( ST2 - a2 - ST1 + a1 ) - 2 tan d1 tan d2 cos ( ST2 - a2 - ST1 + a1 )
   with         B = -2 sin h1 sin d1 / cos2 d1 - 2 sin h2 sin d2 / cos2 d2 + 2 ( sin h1 sin d2 + sin h2 sin d1 ) cos ( ST2 - a2 - ST1 + a1 ) / ( cos d1 cos d2 )
                  C = sin2 h1 / cos2 d1 + sin2 h2 / cos2 d2 - sin2 ( ST2 - a2 - ST1 + a1 ) - 2 sin h1 sin h2 cos ( ST2 - a2 - ST1 + a1 ) / ( cos d1 cos d2 )

-After solving this quadratic equation, we find the longitude L by using the R-P conversion and:

                  2 cos [ L + ( ST2 - a2 + ST1 - a1 )/2 ] cos [ ( ST2 - a2 - ST1 + a1 )/2 ] = E + F
                  2 sin  [ L + ( ST2 - a2 + ST1 - a1 )/2 ] sin  [ ( ST2 - a2 - ST1 + a1 )/2 ] =  E - F

   with        E = ( sin h1 - x sin d1 ) / [ cos d1 ( 1 - x2 )1/2 ]
   and         F = ( sin h2 - x sin d2 ) / [ cos d2 ( 1 - x2 )1/2 ]
 

Data Registers:                R00 thru R03: temp

                 R04 = ST1 - a1                 R08 = ST2 - a2                R12 = ST3 - a3    ........................
                 R05 = Cos d1                   R09 = Cos d2                  R13 = Cos d3
                 R06 = Sin d1                    R10 = Sin d2                    R14 = Sin d3
                 R07 = Sin h1                     R11 = Sin h2                   R15 = Sin h3

Flags:              F22  F29
Subroutines:  "MST"   Mean Sidereal Time at Greenwich  ( cf "Rising-Transit-Setting" )
                        "H0-H"  ( cf "Atmospheric Refraction" )
 
 

  01  LBL "FIX4"
  02  1
  03  STO 01
  04  4.9
  05  STO 02
  06  CF 29
  07  DEG
  08  LBL 01
  09  FIX 0
  10  "DATE^TIME"
  11  ARCL 01
  12  "~?"
  13  FIX 4
  14  CF 22
  15  PROMPT
  16  FC?C 22
  17  GTO 02
  18  XEQ "MST"
  19  LASTX
  20  STO IND 02
  21  FIX 0
  22  "RA^DEC^ALT"
  23  ARCL 01
  24  "~?"   
  25  FIX 4
  26  PROMPT
  27  STO 03
  28  RCL Z
  29  HR
  30  ST- IND 02
  31  15
  32  ST* IND 02
  33  ISG 02
  34  R^
  35  HR
  36  1
  37  P-R
  38  STO IND 02
  39  ISG 02
  40  X<>Y
  41  STO IND 02
  42  ISG 02
  43  RCL 03
  44  XEQ "H0-H"
  45  HR
  46  SIN
  47  STO IND 02     
  48  ISG 01
  49  CLX
  50  ISG 02
  51  GTO 01
  52  LBL 02
  53  CLA
  54  SF 29
  55  RCL 06
  56  RCL 05
  57  /
  58  X^2
  59  RCL 10
  60  RCL 09
  61  /
  62  X^2
  63  +
  64  RCL 04
  65  RCL 08
  66  -
  67  COS
  68  RCL 05
  69  RCL 09
  70  *
  71  /
  72  STO 01
  73  RCL 06
  74  *
  75  RCL 10
  76  *
  77  ST+ X
  78  -
  79  STO 02
  80  RCL 06
  81  RCL 07
  82  *
  83  RCL 05
  84  X^2
  85  /
  86  RCL 10             
  87  RCL 11
  88  *
  89  RCL 09
  90  X^2
  91  /
  92  +
  93  RCL 07
  94  RCL 10
  95  *
  96  RCL 06
  97  RCL 11
  98  *
  99  +
100  RCL 01
101  *
102  -
103  RCL 07
104  RCL 05
105  /
106  X^2
107  RCL 11
108  RCL 09
109  /
110  X^2
111  +
112  RCL 07
113  RCL 11
114  *
115  RCL 01
116  *
117  2
118  STO 00
119  *
120  -
121  RCL 04
122  RCL 08             
123  -
124  SIN
125  X^2
126  ST+ 02
127  -
128  RCL 02
129  *
130  X<>Y
131  X^2
132  X<>Y
133  -
134  SQRT
135  ENTER^
136  CHS
137  R^
138  ST+ Z
139  +
140  RCL 02
141  ST/ Z
142  /
143  STO 01
144  X<>Y
145  LBL 03
146  STO 02
147  RCL 06
148  *
149  RCL 07
150  X<>Y
151  -
152  RCL 05
153  /
154  RCL 11
155  RCL 02
156  RCL 10
157  *
158  -
159  RCL 09
160  /
161  ST- Z
162  +
163  RCL 08
164  RCL 04             
165  -
166  2
167  /
168  SIN
169  ST/ Z
170  X<> L
171  COS
172  /
173  R-P
174  CLX
175  RCL 04
176  RCL 08
177  +
178  2
179  /
180  -
181  X<> 03
182  RCL 02
183  X<> 01
184  DSE 00
185  GTO 03
186  ASIN
187  HMS
188  X<>Y
189  HMS
190  RCL 01
191  ASIN
192  HMS
193  RCL 03
194  HMS
195  END

 
   ( 274 bytes / SIZE at least 012 )
 
 

      STACK        INPUTS      OUTPUTS
           T             /       b2 ( ° ' " )
           Z             /       L2 ( ° ' " )
           Y             /       b1 ( ° ' " )
           X             /       L1 ( ° ' " )

Example:     Once again the same example:  On 2006/04/04,

   at  6h00m  (UT)  alpha Lyr       ( RA = 18h37m09s  , Decl = 38°47'21" )      Altitude = 29°41'59"
   at  6h01m  (UT)  zeta UMaj      ( RA = 13h24m10s , Decl = 54°53'34" )      Altitude = 60°29'56"
   at  6h02m  (UT)  gamma UMin  ( RA = 15h20m43s , Decl = 71°48'43" )      Altitude = 42°26'03"

-SIZE 016 ( or greater )  if you want to use the 3 stars, then:

        XEQ "FIX4"              the HP-41 displays  "DATE^TIME1?"                    ( enter the different data and press R/S )

 2006.0404  ENTER^
       6.00        R/S           --------------------  "RA^DEC^ALT1?"
     18.3709  ENTER^
     38.4721  ENTER^
     29.4159    R/S           --------------------  "DATE^TIME2?"

 2006.0404  ENTER^
       6.01        R/S           -------------------   "RA^DEC^ALT2?"
     13.2410  ENTER^
     54.5334  ENTER^
     60.2956    R/S           -------------------   "DATE^TIME3?"

 2006.0404  ENTER^
       6.02        R/S           -------------------   "RA^DEC^ALT3?"
     15.2043  ENTER^
     71.4843  ENTER^
     42.2603    R/S           -------------------   "DATE^TIME4?"                      ( since we have only 3 stars, press  R/S  without any digit entry )

                      R/S       >>>>   L1 =  -74°40'31''       ( in 12 seconds )
                                   RDN    b1 =   25°49'42''
                                   RDN   L2 = -136°35'18''
                                   RDN    b2 =   77°27'13''

-The system has usually 2 solutions, so if you don't have any idea of your position, use the 3rd star

   8.012004  REGSWAP  XEQ 02  gives

                L1 = -74°40'29''                         RDN   L'2 = 92°13'39''            ( 2 other solutions with stars 1&3 )
   RDN     b1 =  25°49'40''                         RDN    b'2 = 58°20'30''

-Finally   4.012004  REGSWAP  XEQ 02  it yields

               L1 = -74°40'39''                         RDN   L''2 = -114°15'53''         ( 2 other solutions with stars 2&3 )
   RDN    b1 =  25°49'41''                         RDN    b''2 =   35°38'22''

-The arithmetic mean of the 3 ( L1 , b1 )s  is    Longitude = -74°40'33''  ,   Latitude = 25°49'41''

Notes:

-The program doesn't work if a declination = +/-90°  ( DATA ERROR line 57 or 61 ) but in this case, the system is very easy to solve:
-If, for instance,  d1 = 90° then  b = h1 and after substituting this result into the 2nd equation   sin b sin d2 + cos b cos d2 cos ( ST2 - a2 + L ) = sin h2
  ACOS  easily gives the 2 L-values.

-It doesn't really matter to take this case into account because no star has a declination exactly equal to 90° or -90°
-However, roundoff errors may be important - at least in the longitude - if the declination is about +/-89°59'
 

5°)  Program #5
 

-Several bytes may of course be saved if you store the required data in the proper registers before executing the routine.
-"FIX5" uses the same method as "FIX4"
 

Data Registers:                R00 & R11 thru R19: temp              ( Registers R01 thru R10 are to be initialized before executing "FIX5" )

                    •  R01 = Date1                 •  R06 = Date2              YYYY.MNDD
                    •  R02 = Time1                 •  R07 = Time2                 HH.MNSS     ( UT )
                    •  R03 = R.A1                  •  R08 = R.A2                     hh.mnss
                    •  R04 = Decl1                 •  R09 = Decl2                     ° . '  ''
                    •  R05 = h1                      •  R10 = h2                           ° . '  ''

Flags:              There is no real solutions if F00 is set at the end.

Subroutines:  "MST"   Mean Sidereal Time at Greenwich  ( cf "Rising-Transit-Setting" )
                        "H0-H"  ( cf "Atmospheric Refraction" )
                          "P2"    ( cf "Polynomial" §1-a) )
 
 

  01  LBL "FIX5"
  02  DEG
  03  RCL 01
  04  RCL 02
  05  XEQ "MST"
  06  RCL 03
  07  HMS-
  08  HR
  09  STO 11
  10  STO 15
  11  RCL 06
  12  RCL 07
  13  XEQ "MST"
  14  RCL 08
  15  HMS-
  16  HR
  17  ST- 11
  18  ST+ 15
  19  15
  20  ST* 11
  21  2
  22  STO 19
  23  /
  24  ST* 15
  25  RCL 05
  26  XEQ "H0-H"
  27  LASTX
  28  SIN
  29  RCL 04
  30  HR
  31  COS
  32  /
  33  STO 12
  34  RCL 10
  35  XEQ "H0-H"
  36  LASTX
  37  SIN
  38  RCL 09
  39  HR
  40  COS
  41  /
  42  STO 13
  43  RCL 04
  44  HR
  45  TAN
  46  STO 00
  47  *
  48  RCL 12
  49  RCL 09
  50  HR
  51  TAN
  52  STO 14
  53  *
  54  +
  55  RCL 11
  56  COS
  57  STO 16
  58  ST+ 16
  59  *
  60  RCL 00
  61  RCL 12
  62  *
  63  -
  64  RCL 13
  65  RCL 14        
  66  *
  67  -
  68  ST+ X
  69  RCL 00
  70  X^2
  71  RCL 14
  72  X^2
  73  +
  74  RCL 00
  75  RCL 14
  76  *
  77  RCL 16
  78  *
  79  -
  80  X<>Y
  81  RCL 12
  82  ST* 16
  83  X^2
  84  RCL 13
  85  ST* 16
  86  X^2
  87  +
  88  RCL 16
  89  -
  90  RCL 11
  91  SIN
  92  X^2
  93  ST+ T
  94  -
  95  XEQ "P2"     
  96  STO 17
  97  X<>Y
  98  STO 18
  99  LBL 01
100  STO 16
101  RCL 14
102  *
103  RCL 13
104  X<>Y
105  -
106  RCL 12
107  RCL 00
108  RCL 16
109  *
110  -
111  ST+ Z
112  -
113  RCL 11
114  2
115  /
116  1
117  P-R
118  ST/ T
119  RDN
120  /
121  X<>Y
122  R-P
123  CLX
124  RCL 15        
125  -
126  X<> 17
127  DSE 19
128  GTO 01
129  HMS
130  RCL 18
131  ASIN
132  HMS
133  X<>Y
134  RCL 16
135  ASIN
136  HMS
137  RCL 17
138  HMS
139  END

 
  ( 197 bytes / SIZE 020 )
 
 

      STACK        INPUTS      OUTPUTS
           T             /       b2 ( ° ' " )
           Z             /       L2 ( ° ' " )
           Y             /       b1 ( ° ' " )
           X             /       L1 ( ° ' " )

   where   L = longitude , b = latitude

Example:      Still on  2006/04/04,

 •   6h00m  (UT)  alpha Lyr  -  RA = 18h37m09s  , Decl = 38°47'21" ,  Altitude = 29°41'59"
 •   6h01m  (UT)  zeta UMaj  -  RA = 13h24m10s , Decl = 54°53'34" ,  Altitude = 60°29'56"

    2006.0404   STO 01              2006.0404   STO 06
          6            STO 02                    6.01       STO 07
        18.3709   STO 03                  13.2410   STO 08
        38.4721   STO 04                  54.5354   STO 09
        29.4159   STO 05                  60.2956   STO 10

   XEQ "FIX5"  >>>>     L1 =  -136°35'18''                           ---Execution time = 21s---
                         RDN      b1 =     77°27'13''
                         RDN      L2 =   -74°40'31'
                         RDN      b2 =     25°49'42''

-The 2 solutions are  ( L1 , b1 )  &  ( L2 , b2 )