hp41programs

Spherical

Spherical Coordinates for the HP-41


Overview
 

 1°)  3-Dimensional Space

  a)  For the Physicists & Astronomers  ( Focal & M-Code Routines )
  b)  For the Mathematicians

 2°)  n-Dimensional Space

  a)  For the Physicists & Astronomers
  b)  For the Mathematicians
 

1°)  3-Dimensional Space
 

     a)  For the Physicists & Astronomers
 

-We use the following formulae:

       x = r cos b cos L
       y = r cos b sin L
       z = r sin b

   where    x , y , z = rectangular coordinates,    r  = ( x2 + y2 + z2 )1/2  ,   L  = longitude ,  b = latitude

-However, the results can be obtained more easily by the R-P and P-R functions:
 T-register is saved and no data register is used !
-These programs are also listed in "Transformation of Coordinates"
 
 

 01  LBL "R-S"
 02  R-P
 03  X<>Y
 04  RDN
 05  R-P
 06  R^
 07  X<>Y
 08  RTN
 09  LBL "S-R"
 10  X<>Y
 11  RDN
 12  P-R
 13  R^
 14  X<>Y
 15  P-R
 16  END

 
( 30 bytes / SIZE 000 )
 
 

      STACK       INPUTS1     OUTPUTS1      INPUTS2     OUTPUTS2
           T            T            T               T             T
           Z            z            b               b             z
           Y            y            L               L             y
           X            x            r               r             x

 
Example:     x = 2 ; y = 4 ; z = 7         ( in DEG mode )

     7  ENTER^
     4  ENTER^
     2  XEQ "R-S"     r  =  8.306623863
                  RDN     L  = 63°43494882
                  RDN     b =  57°42644430

-And if you execute "S-R" ( or simply press R/S )  with these numbers in X , Y , Z you'll get  x = 2 , y = 4 , z = 7 again

- "R-S" and "S-R" work in all angular modes
 

  >>>  M-Code Routine
 

-These routines perform the same calculations
-There is no check for alpha data and you'll sometimes get -0 instead of 0 ...
 

093   "S"
02D   "-"
012    "R"
104   CLRF 8
02B   JNC+05
092   "R"
02D   "-"
013   "S"
108   SETF 8
2A0  SETDEC
0B8  C=Y
10E  A=C ALL
10C  ?FSET 8
02B   JNC+05
078   C=Z
0A8  Y=C
0AE  A<>C ALL
068   Z=C
0F8   C=X
128   L=C
070   N=C ALL
351   ?NCXQ
084   21D4
10C  ?FSET 8
1D5   ?NCXQ
079   1E75
10C   ?FSET 8
125   ?NCXQ
074   1D49
0E8   X=C
078   C=Z
0A8   Y=C
0AE   A<>C ALL
0F0   C<>N ALL
068   Z=C
0F8   C=X
070   N=C ALL
351   ?NCXQ
084   21D4
10C  ?FSET 8
1D5   ?NCXQ
079   1E75
10C   ?FSET 8
125   ?NCXQ
074   1D49
0E8   X=C
10C   ?FSET 8
023   JNC+04
0F0   C<>N ALL
0A8   Y=C
3E0   RTN
078   C=Z
0A8  Y=C
0F0   C<>N ALL
068   Z=C
3E0   RTN

( 56 words )
 
 

      STACK       INPUTS1     OUTPUTS1      INPUTS2     OUTPUTS2
           T            T            T               T             T
           Z            z            b               b             z
           Y            y            L               L             y
           X            x            r               r             x
           L            /            x               /             r

 
-The same examples return the same results.
-Here, the original content of register X is saved in L-register.

-It's only slightly faster than the focal programs.
-Even in M-Code, the trigonometric functions remain slow.
 

     b)  For the Mathematicians
 

-Slightly different formulas are employed:

       x = r cos µ
       y = r sin µ cos (phi)
       z = r sin µ sin (phi)

   where    x , y , z = rectangular coordinates,    r  = ( x2 + y2 + z2 )1/2  as before
 
 
 

 01  LBL "R-S2"
 02  RDN
 03  R-P
 04  R^
 05  R-P
 06  RTN
 07  LBL "S-R2"
 08  P-R
 09  RDN
 10  P-R
 11  R^
 12  END

 
( 28 bytes / SIZE 000 )
 
 

      STACK       INPUTS1     OUTPUTS1      INPUTS2     OUTPUTS2
           T            T            T               T             T
           Z            z           phi              phi             z
           Y            y            µ               µ             y
           X            x            r               r             x

 
Example:     x = 2 ; y = 4 ; z = 7         ( in DEG mode )

     7  ENTER^
     4  ENTER^
     2  XEQ "R-S2"     r  =  8.306623863
                   RDN      L  = 76°06790845
                   RDN      b =  60°25511870

-And if you execute "S-R2" ( or simply press R/S )  with these numbers in X , Y , Z you'll get  x = 2 , y = 4 , z = 7 again

- "R-S2" and "S-R2" also work in all angular modes.
 

2°)  N-Dimensional Space
 

     a)  For the Physicists & Astronomers
 

-The formulas are generalized as follows:

      xn  =  r sin µn-1
     xn-1 =  r cos µn-1 sin µn-2
     xn-2 =  r cos µn-1 cos µn-2 sin µn-3
     ..........................................................

      x1 =  r cos µn-1 cos µn-2 cos µn-3  ..............  cos µ1
 

Data Registers:               R00 = unused                 ( Registers R01 thru Rnn are to be initialized before executing "RN-SN" or "SN-RN" )

                                      •  R01 = x1                                    •  R01 = r
                                      •  R02 = x2                                    •  R02 = µ1
                                      .................                  or               .................

                                      •  Rnn = xn                                     •  Rnn = µn-1

  >>>  When the program stops, the new coordinates have replaced the inputs in R01 thru Rnn

Flags: /
Subroutines:  /
 
 

 01  LBL "RN-SN"
 02   E3
 03  /
 04  ISG X
 05  ENTER^
 06  ISG X
 07  RCL 01
 08  LBL 01
 09  RCL IND Y  
 10  X<>Y
 11  R-P
 12  X<>Y
 13  STO IND Z
 14  RDN
 15  ISG Z
 16  ISG Y
 17  GTO 01
 18  STO 01
 19  RTN
 20  LBL "SN-RN"
 21  ENTER^
 22  DSE Y
 23  RCL 01
 24  LBL 02
 25  RCL IND Y  
 26  X<>Y
 27  P-R
 28  X<>Y
 29  STO IND Z  
 30  RDN
 31  DSE Y
 32  DSE Z
 33  GTO 02
 34  STO 01
 35  END

 
    ( 67 bytes / SIZE nnn+1 )
 
 

      STACK       INPUT1     OUTPUT1       INPUT2      OUTPUT2
           X           n > 1            r          n > 1             x1

 
Example:     In a 4-dimensional space,   x = 2 ; y = 4 ; z = 7 ; t = 10        ( in DEG mode )

    2   STO 01
    4   STO 02
    7   STO 03
   10  STO 04

    4   XEQ "RN-SN"   >>>>   13 = R01 = r    and

         R02 = µ1 = 63°43494882
         R03 = µ2 = 57°42644430
         R04 = µ3 = 50°28486277

-Then   4  XEQ "SN-RN"  stores the 4 initial numbers  2  4  7  10  in  R01 to R04  again

-These routines work in all angular mode.
-For n = 10 , execution time is about 8 seconds.
 

     b)  For the Mathematicians
 

-The formulas are generalized differently:

      x1  =  r cos µ1
      x2  =  r sin µ1 cos µ2
      x3  =  r sin µ1 sin µ2 cos µ3
     ..........................................................

      xn =  r sin µ1 sin µ2 sin µ3  ..............  sin µn-1
 

Data Registers:               R00 = unused                 ( Registers R01 thru Rnn are to be initialized before executing "RN-SN2" or "SN-RN2" )

                                      •  R01 = x1                                    •  R01 = r
                                      •  R02 = x2                                    •  R02 = µ1
                                      .................                  or               .................

                                      •  Rnn = xn                                     •  Rnn = µn-1

  >>>  When the program stops, the new coordinates have replaced the inputs in R01 thru Rnn

Flags: /
Subroutines:  /
 
 

 01  LBL "RN-SN2"
 02  STO Y
 03  RCL IND X
 04  DSE Y
 05  LBL 01
 06  RCL IND Y
 07  R-P
 08  RDN
 09  STO IND Z     
 10  X<> T
 11  DSE Z
 12  DSE Y
 13  GTO 01
 14  STO 01
 15  RTN
 16  LBL "SN-RN2"
 17   E3
 18  /
 19  ISG X
 20  ENTER^
 21  ISG X
 22  RCL 01
 23  LBL 02
 24  RCL IND Y    
 25  X<>Y
 26  P-R
 27  STO IND T
 28  RDN
 29  ISG Z
 30  ISG Y
 31  GTO 02
 32  STO IND Z     
 33  END

 
     ( 71 bytes / SIZE nnn+1 )
 
 

      STACK       INPUT1     OUTPUT1       INPUT2      OUTPUT2
           X           n > 1            r          n > 1             x1

 
Example:     In a 4-dimensional space,   x = 2 ; y = 4 ; z = 7 ; t = 10        ( in DEG mode )

    2   STO 01
    4   STO 02
    7   STO 03
   10  STO 04

    4   XEQ "RN-SN2"   >>>>   13 = R01 = r    and

         R02 = µ1 = 81°15011690
         R03 = µ2 = 71°85640421
         R04 = µ3 = 55°00797980

-Then   4  XEQ "SN-RN2"  stores the 4 initial numbers  2  4  7  10  in  R01 to R04  again

-These routines work in all angular mode.
-For n = 10 , execution time is about 8 seconds.
-The example above actually returns the polar form of the quaternion  q = 2 + 4 i + 7 j + 10 k