hp41programs

Quat-System Systems of Quaternionic Equations for the HP-41
 

Overview
 

-This program uses the same method that is described in "A Successive Approximation Method for the HP-41":

-If F is a contraction mapping on a complete metric space, then the equation  F ( X ) = X  has a unique solution
 which is the limit of the sequence:  X(k+1) = F(X(k))  where X(0) is arbitrary.

-This theorem is used to solve a system of n equations in n unknowns which must be re-written under the form:
 

      q1 = f1 ( q1 , ... , qn )
      q2 = f2 ( q1 , ... , qn )
       .............................

      qn = fn ( q1 , ... , qn )
 
 

Program Listing
 

Data Registers:       •   R20 = n = the number of unknowns        ( Registers R20 thru R20+5n are to be initialized before executing "FNQ" )

                                  •   R21 to R24 = q1                       •  R21+4n = f1 name            ( q1 , ... , qn )  is an initial guess that you have to choose.
                                  •   R25 to R28 = q2                       •  R22+4n = f2 name
                                       ...............................................................................             R00 to R16 are unused

                                  •   R17+4n to R20+4n = qn           •  R20+5n   = fn name         R17-R18-R19: temp

Flags:  /
Subroutines:      The n functions   fi  computing   fi ( q1 , ... , qn )  in registers X Y Z T assuming  q1 , ...... ,  qn  are in R21 to R20+4n
 
 

 01  LBL "FNQ"
 02  LBL 01
 03  VIEW 21
 04  RCL 20        
 05  4
 06  *
 07  20.02
 08  +
 09  STO 17
 10  RCL 20
 11  +
 12  STO 18
 13  CLX
 14  STO 19 
 15  LBL 02 
 16  RCL IND 18
 17  XEQ IND X
 18  R^
 19  STO L
 20  X<> IND 17
 21  ST- L
 22  X<> L
 23  ABS
 24  ST+ 19
 25  X<> T
 26  ENTER^
 27  DSE 17 
 28  X<> IND 17
 29  -
 30  ABS
 31  R^
 32  ENTER^
 33  DSE 17 
 34  X<> IND 17
 35  -
 36  ABS
 37  +
 38  X<>Y
 39  ENTER^
 40  DSE 17
 41  X<> IND 17
 42  -
 43  ABS
 44  +
 45  ST+ 19
 46  DSE 18
 47  DSE 17
 48  GTO 02 
 49  X<> 19
 50  RND
 51  X#0?
 52  GTO 01
 53  RCL 24       
 54  RCL 23 
 55  RCL 22
 56  RCL 21
 57  END

 
    ( 99 bytes / SIZE 5n+21 )
 
 

      STACK        INPUTS      OUTPUTS
           T             /             t
           Z             /             z
           Y             /             y
           X             /             x

  with  q = x + y i + z j + t k  = one solution

Example:      Find 3 quaternions  u , v , w  such that

   u = ArcSinh ( u v w )
   v = ( u + v + w2 ) 1/3
   w = ( 1 + 2 i + 3 j + 4 k + u + v + w ) 1/2

-We have to load 3 subroutines - for instance:
 
 

  01  LBL "U"
  02  RCL 21
  03  STO 01
  04  RCL 22
  05  STO 02
  06  RCL 23
  07  STO 03 
  08  RCL 24
  09  STO 04
  10  RCL 25
  11  STO 05        
  12  RCL 26 
  13  STO 06
  14  RCL 27
  15  STO 07
  16  RCL 28
  17  STO 08
  18  XEQ "Q*Q"
  19  STO 01
  20  RDN
  21  STO 02
  22  RDN
  23  STO 03
  24  X<>Y
  25  STO 04
  26  RCL 29
  27  STO 05
  28  RCL 30
  29  STO 06
  30  RCL 31
  31  STO 07
  32  RCL 32
  33  STO 08        
  34  XEQ "Q*Q"
  35  XEQ "ASHQ"
  36  RTN
  37  LBL "V"
  38  2
  39  STO 00
  40  RCL 32
  41  RCL 31
  42  RCL 30
  43  RCL 29
  44  XEQ "Q^R"
  45  STO 01
  46  RDN
  47  STO 02
  48  RDN
  49  STO 03
  50  CLX
  51  RCL 24
  52  +
  53  RCL 28
  54  +
  55  RCL 03
  56  RCL 27 
  57  +
  58  RCL 23        
  59  +
  60  3
  61  1/X
  62  STO 00
  63  CLX
  64  RCL 21
  65  RCL 25
  66  +
  67  ST+ 01
  68  CLX
  69  RCL 22
  70  RCL 26
  71  +
  72  ST+ 02
  73  X<> 02
  74  RCL 01
  75  XEQ "Q^R"
  76  RTN
  77  LBL "W"
  78  RCL 21
  79  RCL 25 
  80  +
  81  RCL 29        
  82  +
  83  1 
  84  +
  85  STO 01
  86  RCL 24
  87  RCL 28
  88  +
  89  RCL 32
  90  +
  91  4
  92  +
  93  RCL 23
  94  RCL 27
  95  +
  96  RCL 31
  97  +
  98  3
  99  +
100  RCL 22 
101  RCL 26
102  +
103  RCL 30        
104  +
105  .5
106  STO 00
107  1/X
108  +
109  RCL 01
110  XEQ "Q^R"
111  RTN
112  END

      ( "Q*Q"  "Q^R"  "ASHQ"  are listed in "Quaternions for the HP-41" )

  •   n = 3   STO 20   and if we choose  u = v = w = 1 as initial guesses:

  •   1  STO 21   STO 25   STO 29
  •   0  STO 22   STO 26   STO 30
  •   0  STO 23   STO 27   STO 31
  •   0  STO 24   STO 28   STO 32

  •   "U"  ASTO 33    "V"   ASTO 34   "W"   ASTO 35

  FIX 9   XEQ "FNQ"   >>>>   the HP-41 displays the successive approximations and finally, it yields:         ( Execution time = 14m47s )

                                   >>>>    4.541667578 = R21
                                   RDN     0.195336787 = R22
                                   RDN     0.293005181 = R23
                                   RDN     0.390673575 = R24

-So,  u = 4.541667578 + 0.195336787 i + 0.293005181 j + 0.390673575 k

-Likewise, we find in registers  R25 thru R28 & R29 thru R32:

         v = 2.725387904 + 0.137399822 i + 0.206099734 j + 0.274799645 k

        w = 3.590282794 + 0.377430929 i + 0.566146393 j + 0.754861857 k
 

Notes:

-The accuracy is controlled by the display settings ( line 50 RND )
-FIX 9 may lead to infinite loops:  FIX 8 or FIX 7 are often better.
-Press  XEQ 01  if you want to improve the accuracy then.

-Instead of displaying R21, you could prefer displaying R19:
-Add  VIEW X  after line 49 and delete line 03:
-The successive values must tend to zero if there is convergence.

-It's seldom easy to re-write a given system in the appropriate form and to get convergence...