The Museum of HP Calculators

HP Articles Forum

[Return to the Index ]
[ Previous | Next ]


An Extension for Stefan's Matrix Multi-Tool Program

Posted by Palmer O. Hanson, Jr. on 4 May 2008, 9:24 a.m.

In a thread starting on of November 2, 2007 Stefan Vorkoetter announced that a Matrix Multi-Tool program for the HP-35s was available at his site http://www.stefanv.com/calculators/hp35s_matrix_multitool.html . He noted that his program "... is a long way from being as powerful as the facilities provided by the 15C, 41C/Advantage, or 42s, but it does provide several useful matrix operations in one simple tool. It is loosely modelled after the Advantage Pac matrix program and provides an easy-to-use subset of the functionality of the matrix library. ..."

This program was written to work with Stefan's program and provide more of the matrix processing functions that one finds in machines such as the HP-28S and TI-86. This program relies on Stefan's program for entry and readout of data, and for solution of linear equations. Stefan's program uses one matrix (Matrix A) and one vector (Vector B) for input and output. His program also uses a second matrix (which I shall call Matrix C) during the linear equation solution. Matrix C is not directly accessible through Stefan's input and output routines. This program adds a storage matrix (which I shall call Matrix D). Additional matrix processing functions provided by this program include:

Calculation of Frobenius norm (ABS), the row norm, and the column norm of Matrix A.

Moving of matrices between Stefan's matrix A and either his matrix C or the added storage matrix D using store, recall and exchange commands. Moving of matrices directly between Matrix C and Matrix D is not provided.

Matrix mathematics including the product of Matrix A and Vector b, the product of Matrix A and Matrix C, and the sum or difference between Matrix A and Matrix C.

Special operations such as the dot product of Matrix A and Matrix C, the formation of an identity matrix in Matrix A, the filling Matrix A with a user-defind constant value, and the transpose of Matrix A..

This program uses a menu system similar to that used in Stefan's program. Like Stefan's program it saves labels by having all routines part of the main program label. At program entry and at the completion of each function the menu 1NRM 2MOV 3MTH 4OPS 5XXX appears in the display.

Selection the NRM option brings the menu 1ABS 2COL 3ROW to the display. Pressing any number key other than 1, 2, or 3 and pressing R/S returns the program to the entry menu.. Entering 1, 2, or 3 and pressing R/S brings the Frobenius norm (ABS), the column norm (COL) or the row norm (ROW) of contents of Matrix A to the display. Then pressing R/S returns the calculator to the entry menu. Matrix A is not disturbed by these operations.

Selection of th MOV option from the main menu brings the menu 1STOC 4STOD 2RCLC 5RCLD 3EXCC 6EXCD to the display. Note that there are two spaces between each option in the program listing. This avoids splitting the option nomenclature during display.

The STO commands copy the contents Matrix A into Matrix C or Matrix D.

The RCL commands copy the contents of Matrix C or Matrix D into Matrix A

The EXC commands exchange the contents of Matrix A with the contents of Matrix C or Matrix D.

Selection of the MTH option from the main menu brings the menu 1AxB 2AxC 3A+C 4A-C to the display.

The AxB command multiplies the contents of Matrix A by the contents of Vector B and places the result in Vector B and in the left hand column of Matrix C.

The AxC command multiplies the contents of Matrix A times the contents of Matrix C and places the result in Matrix A. The contents of Matrix A before the multiply are placed in Matrix C.

The A+C command adds the contents of Matrix A and Matrux C and places the result in Matrix A. Tjhe contents of Matrix A before the addition are placed in Matrix C.

The A-C command subtracts the contents of Matrix C from the contents of Matrix A and places the result in Matrix A. The contents of Matrix A before the subtracion are placed in Matrix C.

Selection of the OPS option from the main menu brings the menu 1DOT 2IDN 3FIL 4TRN to the display.

The DOT command calculated the dot product of the contents of Matrix A and Matrix C and delivers the result to the display.

The IDN command replaces the contents of Matrix A with an identity matrix.

The FIL command replaces the contents of Matrix A with a matrix which has all elements equal to a value selected by the user.

The TRN command replaces the contents of Matrix A with its transpose and leaves the matrix which was formerly in Matrix A in Matrix C.

This program includes a dummy option in the main menu which is labeled 5XXX . I have been considering adding an I/O routine so that the user didn't have to move back and forth between Stefan's program and this program, but I haven't done it yet. Including the dummy option means that if I decide to do it later I will simply have to replace the XXX with an appropriate nomeclature and proceed to enter the new option beginning at step N427 of the existing program. The result will be that I will not have to modify existing GTO addresses in the documentation of the present program when and if I decide to make an addition.

The functions of this program assume that the order of the matrix is in N. Any other control variables are calculated inside each individual function. This results in a substantial amount of duplicate code. Furthemore, since I was also trying to expand my programming skill on the HP35s I used different methods of calculating the same control variables.

Program Listing

This program uses a subroutine starting at M389 from Stefan's original Matrix Multi-Tool program. If you are using the revision dated April 3, 2008 then you must change the commands at locations N244 and N289 from XEQ M389 to XEQ M403.

 
N001   LBL N
N002   SF 10
N003   EQN 1NRM 2MOV 3MTH 4OPS 5XXX
N004   CF 10
N005   1
N006   x=y?
N007   GTO N025
N008   x<>y
N009   2
N010   x=y?
N011   GTO N119  
N012   x<>y
N013   3
N014   x=y?
N015   GTO N222
N016   x<>y
N017   4
N018   x=y?
N019   GTO N324 
N020   x<>y
N021   5
N022   x=y?
N023   GTO N427
N024   GTO N002
N025   SF 10
N026   EQN 1ABS 2COL 3ROW
N027   CF 10
N028  1
N029   x=y?
N030   GTO N040
N031   x<>y
N032   2
N033   x=y?
N034   GTO N057
N035   x<>y
N036   3
N037   x=y?
N038   GTO N084
N039   GTO N002
N040   RCL N
N041   x^2
N042   1
N043   -
N044   1000
N045   /
N046   STO I
N047   0
N048   RCL (I)
N049   x^2
N050   +
N051   ISG I
N052   GTO N048
N053   SQRTx
N054   STO A
N055   VIEW A
N056   GTO N002
N057   RCL N
N058   1
N059   -
N060   1000
N061   /
N062   STO I
N063   STO J
N064   CLx
N065   ENTER
N066   0
N067   RCL (I)
N068   ABS
N069   +
N070   ISG I
N071   GTO N067
N072   x<y?
N073   x<>y
N074   RCL N
N075  1000
N076   /
N077   STO+ I
N078   x<>y
N079   ISG J
N080   GTO N066
N081   STO C
N082   VIEW C
N083   GTO N002
N084   RCL N
N085   STO I
N086   1
N087   -
N088   1000
N089   /
N090   STOx I
N091   STO J
N092   RCL N
N093   100000
N094   /
N095   STO+ I
N096   CLx
N097   ENTER
N098   0
N099   RCL (I)
N100   ABS
N101   +
N102   ISG I
N103   GTO N099
N104   x<y?
N105   x<>y
N106   RCL N
N107   x^2
N108   1
N109   -
N110   STO- I
N111   0.001
N112   STO+ I
N113   REGZ
N114   ISG J
N115   GTO N098
N116   STO R
N117   VIEW R
N118   GTO N002
N119   SF 10
N120   EQN 1STOC  4STOD  2RCLC  5RCLD  3EXCC  6EXCD          2 spaces between each
N121   CF 10
N122   1
N123   x=y?
N124   GTO N146
N125   x<>y
N126   2
N127   x=y?
N128   GTO N163
N129   x<>y
N130   3
N131   x=y?
N132   GTO N180
N133   x<>y
N134   4
N135   x=y?
N136   GTO N198
N137   x<>y
N138   5
N139   x=y?
N140   GTO N206
N141   x<>y
N142   6
N143   x=y?
N144   GTO N214
N145   GTO N002
N146   0
N147   STO J
N148   RCL N
N149   x^2
N150   STO+ J
N151   1
N152   -
N153   1000
N154   /
N155   STO I
N156   RCL (I)
N157   STO (J)
N158   1
N159   STO+ J
N160   ISG I
N161  GTO N156
N162   GTO N002
N163   0
N164   STO J
N165   RCL N
N166   x^2
N167   STO+ J
N168   1
N169   -
N170   1000
N171   /
N172   STO I
N173   RCL (J)
N174   STO (I)
N175   1
N176  STO+ J
N177   ISG I
N178   GTO N173
N179   GTO N002
N180   0
N181   STO J
N182   RCL N
N183   x^2
N184   STO+ J
N185   1
N186   -
N187   1000
N188   /
N189   STO I
N190   RCL (I)
N191   x<>(J)
N192   STO (I)
N193   1
N194   STO+ J
N195   ISG I
N196   GTO N190
N197   GTO N002
N198   RCL N
N199   ENTER
N200   x^2
N201   +
N202   1
N203   +
N204   STO J
N205   GTO N148
N206   RCL N
N207   ENTER
N208   x^2
N209   +
N210   1
N211   +
N212   STO J
N213   GTO N165
N214   RCL N
N215   ENTER
N216   x^2
N217   +
N218   1
N219   +
N220   STO J
N221   GTO N182
N222   SF 10
N223   EQN 1AxB  2AxC  3A+C  4A-C
N224   CF10
N225   1
N226   x=y
N227   GTO N241
N228   x<>y
N229   2
N230   x=y?
N231   GTO N252
N232   x<>y
N233   3
N234   x=y?
N235   GTO N301
N236   x<>y
N237   4
N238   x=y?
N239   GTO N303
N240   GTO N002
N241   RCL N
N242   ENTER
N243   x^2
N244   2
N245   x
N246   +
N247   STO E
N248   XEQ M389
N249   CF 0
N250   CF 2
N251   GTO N002
N252   RCL N
N253   ENTER
N254   x^2   
N255   x 
N256   4
N257   /
N258   2
N259   +
N260   INTG
N261   STO T
N262   VIEW T
N263   RCL N
N264   ENTER
N265   x^2
N266   2
N267   x
N268   +
N269   STO E
N270   RCL N
N271   1
N272   -
N273   1000
N274   /
N275   STO V
N276   RCL N
N277   STO J
N278   x^2
N279   STO+ J
N280   STO+ J
N281   STO I
N282   STO+ I
N283   1
N284   STO- J
N285   STO- I
N286   -
N287   1000
N288   /
N289   STO+ I
N290   RCL (I)
N291   STO (J)
N292   DSE J
N293   DSE I
N294   GTO N290
N295   XEQ M389
N296   ISG V
N297   GTO N276
N298   CF 0
N299   CF 2
N300   GTO N180
N301   1
N302   GTO N304
N303   -1
N304   STO S
N305   RCL N
N306   x^2
N307   STO J
N308   1
N309   -
N310   1000
N311   /
N312   STO I
N313   RCL (I)
N314   RCL (J)
N315   RCL S
N316   x
N317   +
N318   STO (J)
N319   1
N320   STO+ J
N321   ISG I
N322   GTO N313
N323   GTO N180
N324   SF 10
N325   EQN 1DOT 2IDN 3FIL 4TRN
N326   CF 10
N327   1
N328   x=y?
N329   GTO N343
N330   x<>y
N331   2
N332   x=y?
N333   GTO N366
N334   x<>y
N335   3
N336   x=y?
N337   GTO N389
N338   x<>y
N339   4
N340   x=y?
N341   GTO N401
N342   GTO N002
N343   RCL N
N344   x^2
N345   STO J
N346   1
N347   -
N348   1000
N349   /
N350   STO I
N351   0
N352   RCL (I)
N353   RCLx (J)
N354   +
N355   1
N356   STO+ J
N357   R Down
N358   ISG I
N359   GTO N352
N360   ENTER
N361   SF 10
N362   EQN DOT =
N363   CF 10
N364   STOP
N365   GTO N002
N366   RCL N
N367   x^2
N368   1
N369   -
N370   1000
N371   /
N372   STO I
N373   RCL I
N374   INTG
N375   RCL N
N376   1
N377   +
N378    /
N379   FP
N380   x=0?
N381   GTO N384
N382   0
N383   GTO N385
N384   1
N385   STO (I)
N386   ISG I
N387   GTO N373
N388   GTO N002
N389   INPUT K
N390   RCL N
N391   x^2
N392   STO I
N393   1
N394   STO- I
N395   RCL K
N396   STO (I)
N397   RCL I
N398   x not equal 0 ?
N399   GTO N393
N400   GTO N002
N401   RCL N
N402   x^2
N403   STO W
N404   STO J
N405   1
N406   -
N407   1000
N408   /
N409   STO I
N410   RCL (I)
N411   STO (J)
N412   RCL N
N413   STO+ J
N414   x^2
N415   2
N416   x
N417   RCL J
N418   x<y?
N419   GTO N424
N420   1
N421   STO+ W
N422   RCL W
N423   STO J
N424   ISG I
N425   GTO N410
N426   GTO N180
N427   GTO N002      

Length = 1532; Checksum = 0AE0

Since some users have reported the length and checksum may not be reliable I have provided some example problems which will demonstrate that the program has been properly entered. We will use three 3x3 matrices
      HP33                           HP15                          Product 

23 15 17 33 16 72 263 150 512

8 11 -6 -24 -10 -57 48 42 51

4 15 12 -8 -4 -17 -324 -134 -771

The matrix at the left is from the demonstration of the Solutions of Simultaneous Equations program on page 1-18 of the hp33s user's guide. The matrix in the center is from the demonstration of a residual correction program on page 121 of the HP-15C Advanced Functions Handbook. The matrix on the right is the product of the matrix on the left and the matrix in the center; i.e., HP33xHP15

1. Use Stefan's program to enter HP15 into Matrix A..

2. Use the NRM functions of this program to calculate the Frobenius norm (ABS) of HP15 as 104.033648403, the row norm (ROW) as 121 and the column norm (COL) as 146 .

3. Use the STOC and STOD functions of this program to store HP15 into Matrix C and into Matrix D. This leaves HP15 in all three matrix locations.

4. Use Stefan's program to enter HP33 into Matrix A.

5. Use the DOT function of this program to calculate the dot product of HP33 and HP15 as 1967.

6. Use the AxC function of this program to calculate the product HP33xHP15. The execution time estimate will be 8 seconds. The product will be in Matrix A and HP33 will be in Matrix C.

7. Use the ABS function of this program to calculate the Frobenius norm of HP33xHP15 as 1,038.197958 .If this is correct you can be reasonably confident that the AxC function is working properly. You can verify the individual elements of the product by returning to Stefan's program.

8. Use the EXCC function of this program to exchange the contents of Matrix A and the contents of Matrix C. This places HP33 in Matrix A and the product in Matrix C.

9. Use the STOD function of this program to store the contents of Matrix A into Matrix D. This places HP33 in Marix D.

10. Use Stefan's program to enter the vector [ 31 17 14 ] in b. Solve and read the determinant of HP33 as 4,598. Read the solution vector X to the problem on page 15-18 of the hp33s user's guide from b as

 9.30622009565E-1
 7.94258373205E-1
-0.13636363636
The inverse of HP33 will be in matrix A and in Matric C. HP33 will still be in Matrix D.

11. Use the RCLD function of this program to recall HP33 from Matrix D and place it into Matrix A . Use the AxB function of this program to multiply HP33 by the solution vector found in step 10. The product HP33xX will be in b and in the left hand column of Matrix C.

12. Use Stefan's program to read out the product HP33xX as

31
17
14.0000000001
13. Use the STO C function of this program to store the contents of Matrix A (HP33) into Matrix C. Use the IDN function of this program to place the 3x3 identity matrix in Matrix A. Use the A+C function of this program to place the sum HP33 and the identiity matrix in Matrix A. The identity matrix will still be in matrix C. Use the ABS function of this program to calculate the Frobenius norm of the sum of HP33 and the identity matrix as 41.7612260356. Again, if this is correct you can be reasonably confident that the IDN and A+C functions are working properly. You can verify the individual elements of the sum with Stefan's program to be
24     15    17

8 12 -6

4 15 13

14. Use the STOC function of this program to store the matrix in Matrix A into Matrix C. Use the FIL function of this program to place a matrix of all two's in Matrix A. Use the EXCC function of this program to exchange the matrices in Matrix A and Matrix C. Use the A-C function of this program to subtract the matrix of all two's from the matrix in Matrix A (which is thes sum of HP33 and the 3x3 identity matrix) in Matrix A.. Calculate the Frobenius norm of the result as 37.0405183549 . Once again, if this is correct you can be reasonably confident that the FIL and A-C functions are working properly. You can verify the individual elements of the difference with Stefan's program to be
22     13     15

6 10 -8

2 13 11

15. Use the EXCD function of this program to bring HP33 to Matrix A. Use the TRN function of this program to place the transpose of HP-33 in Matrix A. Use Stefan's program to verify that the transpose of HP33 is in Matrix A.

Some other subroutine capabilities of Stefan's program:

Entry at M328 will copy the contents of the temporary matrix into matrix A and stop with the contents of the D register in X.

Entry at M383 will stop with a time estimate in the display. When R/S is pressed the product of matrix A and vector B will be placed in the left hand column of the temporary matrix and in vector b. To avoid stopping for the time estimate enter at M389.

Entry at M415 will copy the contents of the left hand column of the temporary matrix into vector b.

Password:

[ Return to the Message Index ]

Go back to the main exhibit hall