TriangSyst

# Triangular Systems for the HP-41

Overview

-This program solves one - or several - linear system(s) whose principal matrix has only zeros above its diagonal.
-It may be used after "triangularizing" a linear system ( Gaussian method, Householder method ... )

B = A.X    where A is a lower triangular matrix.

Program Listing

Data Registers:               R00 is unused                              ( Registers R01 thru Rn.m are to be initialized before executing "TRS" )

•  R01 = b1           •  Rn+1 = a1,1      .....................      •  Rnm-n+1 = a1,n      with  ai,j = 0  for j > i
•  R02 = b2           •  Rn+2 = a2,1      .....................      •  Rnm-n = a2,n

................            ...............................................................................

•  Rnn = bn           •  R2n = an,1         .....................      •  Rnm = an,n

>>>  At the end  x1 , .......... , xn   are in registers R01 to Rnn.

•  This program may be used to solve several linear systems with the same "principal" matrix,
especially if you want to invert the lower triangular matrix itself.

Flags: /
Subroutines: /

 01  LBL "TRS"    02  STO N  03  STO O  04  X<>Y  05  ST* N  06  .1  07  %  08  STO M  09  +  10  STO Q  11  ISG M 12  ISG N  13  LBL 01  14  CLX  15  STO P  16  LBL 02  17  RCL IND N  18  ST/ IND M  19  RCL M  20  RCL IND X  21  SIGN  22  ISG M 23  X=0?  24  GTO 04  25  ISG Y  26  ISG N  27  LBL 03  28  CLX  29  RCL IND N  30  LASTX  31  *  32  ST- IND Y  33  ISG N 34  CLX  35  ISG Y  36  GTO 03  37  RCL P  38  ISG X  39  CLX  40  STO P  41  ST+ N  42  GTO 02         43  LBL 04  44  RCL Q 45  FRC  46  ST+ M  47  LASTX  48  INT  49  X^2  50  DSE X  51  ST- N  52  DSE O  53  GTO 01         54  CLA  55  END

( 96 bytes / SIZE 1+n(c+n) )

 STACK INPUTS OUTPUTS Y n / X c /

where  n = number of raws
and   c = number of systems ( c + n = number of columns )

Example1:     Solve the triangular system:

4 = 2 x
5 = 3 x + 4 y
6 = 5 x + 7 y + 3 z

-Store

4    2    0    0                     R01   R04   R07   R10
5    3    4    0        into       R02   R05   R08   R11
6    5    7    3                     R03   R06   R09   R12

3   ENTER^
1   XEQ "TRS"   >>>>    ( 8 )                                    ---Execution time = 3s---

-And we have

R01 = x =    2
R02 = y = -1/4
R03 = z = -3/4

Example2:    If you want to invert the above square matrix A, store the identity matrix in R01 thru R09 and A in R10 thru R18

R01  R04  R07  R10  R13  R16      1   0   0   2   0   0
R02  R05  R08  R11  R14  R17  =  0   1   0   3   4   0
R03  R06  R09  R12  R15  R18      0   0   1   5   7   3

3   ENTER^
3   XEQ "TRS"   >>>>     ( 8 )                                    ---Execution time = 9s---

-And the inverse is in registers R01 thru R09

R01  R04  R07       1/2       0        0
R02  R05  R08  = -3/8      1/4      0
R03  R06  R09      1/24  -7/12   1/3

Notes:

-The square matrix itself is unchanged
-Since synthetic registers P & Q are used, don't interrupt "TRS",
this could change the contents of these registers.
-The alpha register is cleared at the end.

Variant:

-You can also avoid to store the zero-elements of the matrix ( above the diagonal ).
-In this case,

add   LASTX   +   ENTER^   SIGN   ST+ X   /     after line 49
replace line 42 by  GTO 01
delete lines 37 to 41 and lines 14 to 16                          ( 53 lines / 90 bytes )

-In example 2, store

R01  R04  R07  R10  R13  R15      1   0   0   2   4   3
R02  R05  R08  R11  R14          =  0   1   0   3   7
R03  R06  R09  R12                       0   0   1   5

3   ENTER^
3   XEQ "TRS"   >>>>     ( 5 )                                    ---Execution time = 8s---

-And the inverse is still in registers R01 thru R09

R01  R04  R07       1/2       0        0
R02  R05  R08  = -3/8      1/4      0
R03  R06  R09      1/24  -7/12   1/3

-Since the SIZE becomes  1 + c n + n(n+1)/2  so you can solve a triangular system of 23 equations in 23 unknowns.