Home

SandMatrix_4 Manual

image

Contents

1. c Angel Martin August 2013 Page 78 SandMatrix_4 Manual input display XEQ INTPOL X 473 15 R S X0 480 R S YO 1 7905 R S Y 1 79050 R S X1 450 R S Y1 0 9322 R S Y 1 59452 R S X2 500 R S 12 2 2 6392 R S Y 1 55067 R S X3 400 R S Y3 0 24577 R S Y 1 55453 R S X4 530 R S Y4 4 4569 R S Y 1 55495 linear interpolation quadratic interpolation cubic interpolation 4th order From this we conclude that 1 55 MPa is a reasonably good estimate and that the linear interpolation was certainly not sufficient Incidentally the true value is 1 554950 MPa The program listing is shown below 2 FC 55 34 AIP 3 SF 21 35 X lt gt Y 4 X 36 y 5 PROMPT x value of point E PROMPT prompts for Yk STO 00 38 DSE02 gt 7 3 05 39 GTOO02 8 STO 01 40 LBLO3 i 41 RCLIND 02 10 RCL 01 42 A INT 43 LASTX 12 E 44 RAZ 13 Fr a5 l 14 E3 E 1 00 k 1 46 ISG02 135 B 47 RCLIND02 1346 l 4 00 k 1 48 LASTX 17 STO 02 49 18 RCL 01 50 ST Z 49 INT 51 LASTX 22 3 52 RDN za 53 RDN o 2 2 54 of 23 55 LBL02 a 24 y 56 STO IND 01 25 AIP 57 ISG02 r 26 Jo 58 GTOO3 27 PROMPT prompts for Xk 59 y 28 RCL 00 60 ARCLX 29 6l AVIEW 30 STO IND 01 f 62 ISG01 C 31 ISG 01 63 GTOO1 next order f 32 ye f 64 END done c Angel Martin August 2013 Page 79 Sa
2. A logical enhancement to this routine would be to change the matrix name back to its original one removing the tilde This can be done in two ways 1 creating a new matrix file and copying it over once again or preferable 2 using RENMFL in the AMC_OS X module to rename the X mem file c ngel Martin August 2013 Page 42 SandMatrix_4 Manual Finding an element within a Matrix plus an easy driver for M M will search a given matrix looking for an element that equals the value in the X register If it is found it returns its location pointer to the X reg and leaves the pointer set to it If it s not found it returns 1 to X and the pointer is outside the matrix You can further use this result adding the conditional test function X gt 0 available in the SandMath right after MFI ND which in a program will skip a line if the element wasn t found Below are the program listings for your perusal 1 LBL MFIND MNAME in Alpha LBL MATP E 2 DIM1 M1 dimension sets pointer to 1 1 3 PROMPT prompt for it 4 M1 matrix name M1 target value to X reg 5 MATDIM create matrix in X mem recall element 6 PMTM input elements equal 7 DIM2 M2 dimension yes exit 8 PROMPT prompt for it no increase column 9 M2 matrix name M2 end of matrix 10 MATDIM create matrix in X mem no next element 11 PMTM input elements target value to X reg 12 DIM 13 FRC of columns for M2 14 M1 put 1 in X
3. third row 4 ENTER 6 ENTER 4 R S 6 0000 SF 06 6 0000 Sets it in subroutine mode XEQ EI GEN LO V Prompts for lower bound 5 R S HI V Higher bound 15 R S flying goose FROOT is working on it EV 10 00000 ev found in FIX 5 The original matrix is not modified in any way but note that an auxiliary matrix is created for the calculations This scratch matrix is not purged automatically from X Mem you ll have to do that after you re done calculating as many eigenvalues as you need Below is the program listing for EIGEN Note how the equation to solve already requires an auxiliary FAT entry since a global label is always needed by FROOT You can refer to the SandMath manual if you need to refresh your understanding of FROOT and FINTG c Angel Martin August 2013 Page 59 SandMatrix 4 Manual 1 26 scratch matrix 2 LU FORM warning text A MATDIM as identity one 3 AVIEW display it 28 4 MNAME MNAME back to Alpha 29 LOW V 5 STOP your chance to fix it 30 PROMPT prompt lower bound 6 GTO 01 try again 310 HI V 7 o LBL EIGEN 32 PROMPT prompt upper bound 8 ASTO 00 save MNAME in ROO d 33 CCD MATRX show RUNNING i 9 FS 06 subroutine mode r 34 HEV d 10 GTO 01 yes skip data entry 35 FROOT Solve for Ev 11 SNDMATRX4 prompts ORDER 36 TONE4 found 12 STOP 370 EVs B E 38 ARCLX 14 E3 E 1 001
4. 7 R S R2 prompts for the second row 8 ENTER 9 ENTER 10 R S done c ngel Martin August 2013 Page 25 SandMatrix 4 Manual This section briefly defines the matrix functions besides the dimensioning storing and recalling functions discussed above Note that most of these functions are not meaningful for matrices containing Alpha data and that many of these functions are not meaningful for complex matrices In any case a complex matrix appears as a real matrix to all functions except CMEDIT Refer to Working with Complex Matrices for more information on using these functions with complex matrices 2 3 1 Matrix Arithmetic Adds scalar or element to each element A B C or X B C in Alpha Subtracts scalar element to each element A B C or X B C in Alpha Multiplies scalar element to each element A B C or X B C in Alpha Divides each element by scalar or element A B C or X B C in Alpha Calculates the true matrix product A B C in Alpha The matrix arithmetic functions provided are scalar addition subtraction multiplication and division as well as true matrix multiplication The scalar arithmetic functions can use two matrices as operands or one scalar and one matrix When using two matrices the matrices do not have to be of the same dimension but the total number of elements in each must be the same This also applies to the result matrix Note that the i j notation below assumes that the dime
5. ES Matrix Size MSZE Header Z MSZE Header E MSZE Header M ngel Martin MSZE PORT DEP Jumps to Bank_2 MSZE XQ adds 4 to XS gt A5D9 LNCHO valid for main and X mem lt parameter gt O o N DW Bi WN Be the proper way to do it 00B JNC 01 100 ENROM1 restore bank 1 MSZE OBO C N ALL header register MSZE 106 A C SEX MSZE 17D PNC GO BIN BCD plus RCL MSZE 0C6 gt 315F ATOX20 PMAT is nothing more than a user friendly driver program to automate the complete matrix product procedure without any need to dimension the result matrix in advance The routine will guide you step by step thru the complete sequence including the element data input and output c ngel Martin August 2013 Page 41 SandMatrix 4 Manual is a good example of a sorely missing function the majority of matrix algorithms involve identity matrices one way or another so having a routine that does the job becomes rather important The SandMatrix routine follows a single element approach storing ones in the main diagonal after zeroing the matrix first This is faster and more convenient that block based methods even if not requiring scratch matrices for intermediate calculations See an the example below courtesy of Thomas Klemm DIM n 1 n a DIM n n 1 1 1 11 0 0 O 11 O 0 111 gt 000 gt 1000 gt 1010 JO O Of 11 0 0 O Jo O 1 jo 0 0 1 LBL MIDA MNAME in Alpha 1 LBL IDNZ 2 MZERO clear all
6. forms the matrix dimensions N 1 00 N 1 08 MX specifies matrix MX to be created in X Mem 09 MATDI M creates and dimensions matrix MX in X MEM 10 0 specifies first row first column and 11 MSI resets the row column indexes 12 LBL 00 loop to ask for data amp compute MX elements 13 MRIJ recalls the current value of the indexes 14 X forms the prompt to ask the user to enter xi 15 AI P appends the index to the prompt 16 J appends to the prompt 17 PROMPT prompts to enter xi and resume execution 18 ENTER fills the stack with the value of xi 19 ENTER in order to compute all powers of xi 20 ENTER from 1 to xi n and store them in MX 21 1 initializes the value of xi 0 i e 1 22 MSR stores it in MX and updates the indexes c Angel Martin August 2013 Page 82 SandMatrix_4 Manual Notes 23 LBLO1 25 MSR 26 FC 09 27 GTOO1 28 FC 10 29 GTO00 30 CLA 31 DIM 32 INT 33 my 34 MATDIM 35 LBLB 36 0 37 MSI 38 LBL02 39 MRIJ go y 4 AP 42 43 PROMPT 44 MSR 45 FC 10 46 GTOO2 47 MX MY 48 MSYS 49 LBLC 50 0 51 MSIJ 52 LBLO03 53 MRIJ 54 A 55 AIP 56 j 57 MRR 58 ARCLX 59 PROMPT 60 FC 10 61 GTOO03 62 END loop to compute the powers of xi 24 computes xi j stores it in MX and updates the indexes are we done with this row not yet go back for the next xi power row done Are we done with all rows not yet go back to ask for the n
7. 1 2 1 3 1 4 1 3 1 4 1 5 We ll use to input the element vaules as PMTM is not really suitable for this example Previously we need to create the matrix as follows ALPHA HILB3 3 003 XEQ MATDI M Once all elements are entered we execute MSQRT which shows the norms of the different iterations Let s assume we set the calculator in FIX 9 for the maximum accuracy available then the result matrix is as follows Final Frobenius norm 1 238278374 0 917390290 0 345469265 0 197600714 Sqrt A 0 345469265 0 374984280 0 270871020 0 197600714 0 270871020 0 295943995 Squaring the result matrix again you can use for that we can check the accuracy 0 999999999 0 499999999 0 333333333 Sqr A 2 0 500000000 0 333333333 0 250000000 0 333333333 0 249999999 0 200000000 which isn t bad at all for a 33 years old calculator indeed c Angel Martin August 2013 Page 47 SandMatrix 4 Manual Example 2 Find a square root of the 4 x 4 matrix below and check the accuracy by squaring it back 36 97 17 89 33 68 42 J 206 48 34 104 39 92 27 30 Using FIX 4 and PMTM for the data input nice integer values the result is as follows 8 0000 6 0000 1 0000 7 0000 7 0000 1 0001 8 0000 3 0000 8 0001 6 0000 8 0000 6 0000 6 0000 7 0000 7 0000 3 0000 SORT A which is exact to 4 decimal places save a couple of u ps here and there The program listing is shown below Note th
8. 39 PROMPT display result d 15 n 00n 40 GTO 00 next guess 16 MEV hard coded name 41 LBL EV subroutine dl 17 MATDIM create square matrix 42 i IMR input elements 43 MIDN make matrix identity r a X ASTO 00 T 45 MAT multiply it by scalar guess g 21 DIM get dimension 46 q i 22 l J not square 47 ARCL 00 prepare Aplha string 23 ADV MATRX show error 4g 24 LU LU decomposed 49 MAT calculate the eigen matrix d 25 GTO 02 yes warning loop 50 MDET get its determinant 51 END return works for N dimensional orders In that regard its execution time provided that a decent initial guess is given compares favorably to that of CHRPOL the other program that calculates eigenvalues The difference of course is that CHRPOL obtains a the eigen values simultaneously whilst does it one at a time When compared to other approaches the program listed above is almost minimalistic that s its real benefit and the reason that justifies its inclusion in the SandMatrix module However relying on FROOT is clearly not a robust approach to calculate eigenvalues The calculation of the characteristic polynomial using dedicated methods is a necessity c Angel Martin August 2013 Page 60 SandMatrix_4 Manual 3 Dimensional case EV3X3 Let s start with the particular case n 3 In this scenario there are simple formulas to calculate the characteristic polynomial which make the calculations
9. 9 add to partial result q MATDIM add one more column 10 FC 09 end of row 10 TRAPS transpose it 11 no next row 11 INT 12 FC 10 end of matrix 12 MATDIM make it a column matrix 13 GTO 05 no next element 13 SUM summ all elements 14 END done 14 PURFL purge scratch 15 AS WAP bring focus to original 16 CLAC alpha housekeeping 17 ABSP to erase all tracks 18 END Row Division by Diagonal element Diagonal Unitary R aRR The last function in this chapter is used to modify the values of all elements dividing each row by its diagonal element that is aij aij at j 1 2 n In effect the result matrix has all its diagonal elements equal to 1 i e diagonal unitary This type of calculation is useful for row simplification steps in matrix reductions more like a vestigial function from when the major matrix operations were not available i e the CCD days pre Advantage Pac MNAME in Alpha 19 RDN discard product 2 DIM get dimansion 20 FC 09 end of row 3 IHJ not square 21 GTO 00 no get next element 4 ADV MATRX show error 22 FS 10 end of matrix 5 0 23 GTO 02 yes exit 6 MSIJA set pointer to 1 1 24 MRIJ recall pointer 25 ENTERA 8 MR recall diag element 26 INT 9 1 X inverse value 27 ENTER 10 X lt gt Y pointer to X 28 I lt gt J does E3 if integer 11 MSIJ set pointer 29 j 00j 12 X lt gt Y value back to X reg 30 MSIJ set pointer 13 ENTER 31 X lt gt Y 14 ENTERA fill stack w value GTO 01 next row 15
10. CON Ln A PAHC SEX JC 09 7 A ENPE ee eee FSET 12 digits input already JNC 16d gt ONE PROMPT CLRF 10 F clear CHS flag CLRF 11 allow RADIX CLRF 12 set SPACE flag PNC XQ o add space to LCD gt 0FD5 DSPL20 JNC 14d sl MM add to Alpha LDI SEX CON EE PAHC S amp X terminate digit entry _INC 15d WAYOUT nni LDI S amp X CON L _ PAHC SEX JNC 04 Bee gt 0899 BLINK1 JINC 17d_ _ gt ___JONEPROMPT_ 2 FSET 10 ua been used already JC 02 ONE PROMPT SETF 10 a first time nn Y O KEN appends WRIT 15 e ae 9 bit LCD write INC 32d TT Oe JPOALPHY 222222 E NC XQ Left justify LCD gt 2BF7 LEFTJ Page SandMatrix 4 Manual 67 ALIST Po lasor Mi NC XQ Clear LCD and reset things 68 ALIST 124 gt 4958 EXIT3 69 ALIST 175 PNC XQ Adjust F10 Status 70 ALIST 114 gt 455D ADJF10 71 ALIST aces a Normal Function ReturnKB 72 ALIST 002 gt 00C7 NERKB 73 ALIST DELCHR_ 4515 3B8 READ 14 d todeleterightmostchr 74 ALIST 158 M C ALL save it for later 76 ALIST 024 gt 0952 ENCPOO 77 ALIST 178 READ 5 M 78 ALIST 451A 2EE CHO ALL anything in Alpha 79 ALIST 451B 037 JC 06 yes goon 80 ALIST 104 CLRF 8 no abort if empty 81 ALIST PNC XQ rz Mainframe Message 82 ALIST gt 1C6C MSGA 83 ALIST 03C NULL from table 84 ALIST fixed bug JNC 17d Reset everything and leave 85 ALIST P fazna BE PNC XQ remove
11. c ngel Martin August 2013 Page 46 SandMatrix_4 Manual Square root of a Matrix MSQRT In mathematics the square root of a matrix extends the notion of square root from numbers to matrices A matrix B is said to be a square root of A if the matrix product BB is equal to A Just as with the real numbers a real matrix may fail to have a real square root but have a square root with complex valued entries In general a matrix can have many square roots however a positive semidefinite matrix M that satisfy that x M x gt 0 for all x in R has precisely one positive semidefinite square root which can be called its principal square root Computing the matrix square root in the SandMatrix uses a modification of the the Denman Beavers iteration Let YO A and ZO I where I is the n x n identity matrix The iteration is defined by Yet 5 Y a Zo k Za a Y gt Convergence is not guaranteed even for matrices that do have square roots but if the process converges the matrix Yk converges quadratically to a square root A while Zk converges to its inverse 471 Contrary to the exponential and logarithm programs the square root convergence is checked using the rounded values of the norms for two consecutive iterations You can set FIX 9 for maximum accuracy and longest run time not a problem on V41 and on the 41CL of course Example 1 Find a square root of the 3 order Hilbert matrix 1 1 2 1 3 A
12. 15 STO IND Y stored in Rn 1 67 E 16 ASWAP 68 n 1 17 MAT avoids LU issues 69 E6 18 DIM 70 0 000 00 n 1 19 auxiliary array 71 3 build the from to 20 MATDIM 72 E3 E 1 003 21 FRC 0 00n 73 1 003 00 n 1 22 2 74 REGMOVE as expected by RTSN 23 2 00n 75 RTSN 24 STO 00 76 GTO 00 A go to EXIT 25 CF21 not halting VIEW 77 LBLO4 MN 78 X Y n 4 27 VIEW 00 shows index 79 GTO 03 28 80 RCL 02 a3 29 MIDN I 81 RCL 03 a2 30 p 82 RCL 04 al 31 MTRACE tr B 83 RCL 05 a0 32 RCL 00 84 QUART 33 INT k 1 85 GTO 00 gt go to EXIT 34 E 86 LBLO3 E 35 k 87 RCL 01 a3 36 88 RCL 02 a2 37 CHS 89 RCL 03 al 38 STO IND 00 pk tr B k 90 RCL 04 a0 39 X HH 91 CROOT 40 MAT pk I 92 x 41 PAHH 93 ARCL Z 42 MAT 4 B p I 94 PROMPT real root 43 CLA 95 FC 43 is RAD on 44 ARCL 01 96 GTO 01 yes complex roots 45 P 97 X lt gt Z no real roots 46 M M B A B pl 98 CLX so we clear Z 47 ISG 00 99 X lt gt Z 48 GTOOO 100 LBLO1 MA 49 DIM n 00n 101 QROUT output roots 50 FRC 0 00n 102 LBL 00 51 E 103 MNAME bring MNAME back 52 STO 01 it s monic 104 END done c Angel Martin August 2013 Page 64 SandMatrix_4 Manual Particular case Symmetric Matrices f ACOBI For symmetric matrices the Jacobi algorithm provides a faster method JACOBI was written by Valent n Albillo and published in PPC TN ViN3 October 1980 As with CHRPOL I ve only slightly adapted it to the SandMatrix bu
13. 344 44 ALIST 44F8 355 45 ALIST 44F9 03C 46 ALIST 44FA 1393 47 ALIST FAB 1130 43 ALIST 44FC 1370 49 ALIST 44FD 366 50 ALIST 44FE 07B 51 AUST 44FF 30 52 ALIST 4500 230 53 ALIST 4501 366 54 ALIST 4502 023 55 ALIST 4503 265 56 ALIST 4504 020 57 ALIST 4505 37B 58 ALIST 4506 locc 59 ALIST 4507 3F7 60 ALIST o 4508 0c8 61 ALIST 4509 130 62 ALIST 450A 02D 63 ALIST 450B 3E8 64 ALIST 450C 303 65 ALIST WAYOUT 450D 3DD moea Aeh S PrF OAC 0 ngel Martin August 2013 M A _ ee Delete char plus logic gt 4515 PNC XQ gt 0E45 JNC 04 FSET 3 JNC 18d DELCHR Partial Data Entry LT BcKARW numeric input NO KEEP LOOKING A lt gt C MS recall LS digit from A 13 LDI SEX CON move it to C S amp X write it in display 9 bit enable SPACE RCR 13 WRIT 15 e SETF 12 a ce ea lt 1 em ee ee en ele eee g G C PT ae ae NC XQ AN Disable PER enable RAM gt 0952 ENCPOO O gt 2D14 APNDNW C 0 PT Eje G C PT reset PTEMP bits PNC XQ TEI Enable Display not cleared gt 07F6 ENLCD JNC 21d gt ONE PROMPT _ FSET 7 Ea decimal key pressed NO KEEP LOOKING been used already ONE PROMPT no more radix unless deletion adds proper radix sign RADIX4 FSET 11 JC 04 SETF 11 NC XQ gt 4543 JNC 18d C N ALL PRESSED KEY CODE ARES alaaa LDI SEX
14. MATDI M 2 003 Dimensions matrix ABC in X Mem 0 XEQ MSI J A 0 000 Sets pointer to 1 001 position 5 XEQ MSR 5 000 Enters element and advances pointer to next column for next entry 6 XEQ MSR 6 000 Ditto as above 7 XEQ MSR 7 000 Pointer automatically moves to second row also setting flag 09 8 XEQ MSR 8 0000 9 XEQ MSR 9 0000 10 XEQ MSR 10 0000 This sets both flags 09 and 10 SF 08 This sets the editor to display only XEQ MEDI T 1 1 5 0000 R S 1 2 6 0000 R S 1 3 7 0000 R S 2 1 8 0000 R S 2 2 9 0000 R S 2 3 10 0000 Updated Matrix Editor Row Input mode From the examples of MPOL we have already seen another more effective way to enter the element values using PMTM instead of MEDIT to handle them one row at a time This drastically speeds up the process although some limitations apply e The maximum length for all values and the blank spaces in between them is 24 characters as it uses the Alpha register to temporarily hold them e Decimal and negative values are supported in this mode but values with exponential notation i e 2 4 E23 cannot be entered using PMTM Here s the how the sequence would change using this approach Keystrokes Displa Comments ALPHA LPHA ABC 2 003 XEQ MATDI M 2 003 Dimensions matrix ABC in X Mem XEQ PMTM R1 prompts to enter the first row 5 ENTER 6 ENTER
15. R S a3 3 5 R S a3 4 3 CHS R S a4 4 2 input the last element 2 R S PREC Asks for precision 5 R S RUNNING Scrolling on the display X 0 03302 R S X 98 52170 After a while 2 5m in normal 41 R S X 1 18609 the four ev s are displayed R S X 0 25920 Example Repeat the same case but using CHRPOL to obtain the polynomial and its roots Keystrokes Displa Result ALPHA AA ALPHA current X reg Matrix name in Alpha 4 004 XEQ MATDI M XEQ PMTM 4 003 Ri i ma 25 ENTER CHS 41 ENTER 10 ENTER CHS 6 R S CHS 41 ENTER 68 ENTER CHS 17 ENTER 10 R S AN R2 rr lt M R3 lt M 10 ENTER CHS 17 ENTER 5 ENTER CHS 3 R S R4 lt M CHS 6 ENTER 10 ENTER CHS 3 ENTER 2 R S XEQ CHRPOL R S R S R S R S RUNNING Ex aK XAK a4 1 a3 100 a2 146 al 35 a0 1 00000 RUNNING X1 98 52170 X2 1 18609 X3 0 25919 X4 0 03302 Creates mtrix in X Mem prompts for row 1 prompte for row 2 prompts for row 3 prompts for row 4 Scrolling on the display Reminder of convention Coefficient of x 4 Coefficient of x 3 Coefficient of x 2 Coefficient of x First coef independent term Scrolling on the display Frst root Second root Third root Fourth and last root The solution is Chr A x 4 100 x 3 146 x 2
16. s is smaller than the convergence criteria The precision factor is calculated as follows e abs dp abs dq abs p abs q The program dimensions and populates matrices RS and CN to hold the current values of p q and the coefficients Cn respectively e RS is the column matrix of dimension 2x1 e CN is the coefficients matrix of dimension 2x2 The linear system is solved as many times as iterations needed to establish the convergence With each factorization the program obtains two roots This is repeated for until all roots have been found Program Details In manual RUN mode PROOT prompts first for the order n ie the degree and for each of the coefficients sequentially It then presents the option to store the roots into a matrix in X Mem To use it you just have to press Y at the prompt below All roots are stored in matrix ROOTS of dimension n x 2 with the first column holding the real parts and the second the imaginary parts of each root assumed complex The global label RTSN is meant to be used in subroutines It expects the degree stored in ROO and the coefficients stored in registers RO3 until R 3 n Registers RO1 and RO2 are used internally and cannot be used for your data In subroutine mode the roots will always be stored in the matrix ROOTS Example 1 Find the five roots of the polynomial below P x 2 x 7 x 20 x 81 x7 190 x 150 Keystrokes
17. x 3x 4x 4 5 and 4 2 3 A 325 2 1 4 This is also a good example to become familiar with the editor and input routines available in the SandMatrix First we ll create and populate the matrix using the Matrix Editor input functionality very recommended for integer elements as follows ALPHA A lALPHA 3 003 XEQ MATDI M creates the matrix in X Mem then XEQ PMTM gt at the prompt R1 _ we type 4 ENTER 2 ENTER 3 R S gt at the prompt R2 _ we type 3 ENTER 2 ENTER 5 R S gt at the prompt R3 _ we type 2 ENTER 1 ENTER 4 R S The Matrix has been completely input using batches or lists including all elements of each row simultaneously this is an advantageous way to handle them that results in faster and less error prone method not based on a single element prompt Note how pressing ENTER during this process results into a blank space in the display separating each of the elements and that the sequence is terminated pressing R S Upon completion the matrix elements are stored in the Matrix file in extended memory The analogous function for the polynomial is PMTP which requires the control word in x a number of the form bbb eee denoting the beginning and ending registers that contain the polynomial coefficients In this case 2 006 XEQ PMTP gt atthe prompt R2 _ we type 2 ENTER CHS 1 ENTER 3 ENTER
18. 015156701 0 057916477 A 0 019601835 0 953558110 0 020490861 0 017823781 0 045426856 0 974937998 1 199999994 0 100000000 0 300000000 A7 gt 0 100000000 0 800000000 0 100000000 0 100000000 0 200000000 0 900000000 c ngel Martin August 2013 Page 49 SandMatrix 4 Manual Program listings for MPWR and M 1 X MNAME in Alpha 1 LBL M 2 MNAME in Alpha 2 DIM get dimension 2 DIM get dimension 3 l J square 3 IHJ is it square 4 ADV MATRX yes show error 4 ADV MATRX yes error message 5 CCD MATRX no show RUNNING 5 CCD MATRX no show Running 6 X lt gt Y power index to X reg 6 ASTO L 7 INT make integer 7 fa 8 X 0 is it zero 8 ARCL L 9 GTO 01 no skip over 9 J P M M P 10 MIDN yes make identity 10 ASWAP M P M RTN done 11 ASWAP P M M 12 MATDIM auxiliary P 13 X lt 0 is it negative 13 ASWAP M M P 14 MINV yes invert matrix 14 M M matrix product 15 ABS 15 CLAC MM 16 E 16 CLAC M 17 n 1 17 J P M P 18 X 0 was n 1 18 ASWAP P M 19 RTN yes we re done 19 MAT result to M 20 STO 00 store in ROO 20 PURFL purge P 21 ASTO 01 store Mname in R01 21 MNAME MNAME to Alpha 22 22 END done 23 MAT copy to aux matrix 24 DIM get dimansion 25 p 26 MATDIM auxiliary matrix P prepare alpha string MNAME in Alpha H 2 1 X 29 ARCL 01 MNAME 3 STO 05 store in ROS 30 ja ft MNAME P 4 MLN matrix logarithm 31 M M matrix product 5 RCL 05
19. 1 A 3 5 7 and B 5 9 2 7 9 8 6 5 3 The results are ALPHA A B C ALPHA 15 11 23 XEQ MLI E gt Lie AB 24 19 65 58 85 34 ALPHAL B A C ALPHA 15 11 23 XEQ MLI E gt Lie B A 24 19 65 58 85 34 The program listing is shown on the left Note the usage of auxiliary matrix to temporatily hold the result of the two matrix products always the same limitation imposed by M M and the extensive usage of the alpha string management functions like ASWAP necessary to deal with the three matrix names in the string In fact SWAP swaps the contents of the Alpha register around the first comma character encounterd which makes it so interesting in this case 1 LBL MLIE OPI OF 2 RES in Alpha 15 ARCL RESA RES E MEQ 00 colculate OPIJTOP2 16 MAT 3 5T lt gt A complete string to stack 17 a 4 MNAME F RES 18 PURFL purge 5 ASTO 00 19 MINAME 6 STEA restores complete siring 20 RTN done T CLAC OP1 0P2 2 LBL E ABSP OP1 0P2 22 DIM get dimension 9 ASWAP OP2 0P1 23 ASWAP OP RES OPI 10 Mp OP1 0P2 8 24 ASWAP RES OP1 OP2 11 MEQ 00 colculote OP2 OP1 25 MATDIM create RES 12 CLA 26 ASWAP OFI OPZ RES 13 ARCL 00 RES 2d M M matrix product 14 e RES E 28 END return c ngel Martin August 2013 Page 52 SandMatrix_4 Manual Matrix Trace and remaining functions MTRACE In linear algebra
20. 1E 7 Eigen Values by Solve Eigen Values by Formula Eigen Values by Formula Eigen Values by Jacobi shows results W amp W GmbH W amp W GmbH W amp W GmbH W amp W GmbH W amp W GmbH W amp W GmbH W amp W GmbH HP Co W amp W GmbH HP Co HP Co ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin ngel Martin JM Baillard ngel Martin JM Baillard ngel Martin ngel Martin ngel Martin Valent n Albillo Eugenio beda shows results ngel Martin shows results ngel Martin shows results ngel Martin Page 8 p p Polynomial Division Driver for PDIV shows results ngel Martin PCPY Copy of Polynomial from to cntl words in Y X polynomial copied JM Baillard PDIV Euyclidean Division cont words in Y and X cntl words remainder amp result JM Baillard PEDIT Polynomial Editor cntl word in X prompts for each coeff value Angel Martin PFE Partial Fraction Expansion Under prgm control see description to decode JM Baillard PF gt X Prime Factors to Number Matrix w Prime Facts in XMEM restores the o
21. 3 Matrix Functions Matrix Arithmetic 26 Major Matrix Operations 27 LU Decomposition 28 Working with Complex Matrices 29 Using Functions with Complex Matrices 31 Other Matrix Functions Utilities 34 Moving and Exchanging sections 34 Maxima and minima 35 Norms and Sums 35 c ngel Martin August 2013 Page 3 SandMatrix 4 Manual 3 Upper Page Functions in Detail 3 1 Advanced Matrix The Enhanced Matrix Editor s 37 New Matrix Utilities housekeeping 40 Finding elements Driver for M M 43 Exponential of a Matrix 44 Logarithm of a Matrix 45 Square Root of a Matrix 47 Matrix Integer Powers and Roots 49 Lie Product 52 Matrix Trace 53 Unitary Diagonal 54 Sum of Diagonal Crossed element products 55 Appendix Square root of a 2x2 matrix 56 3 2 Polynomials and Linear Algebra Eigenvectors and Eigenvalues 57 Characteristic Polynomial 58 SOLVE based implementation 59 Formula based 3 Dimensional Case 61 General n dimensional case Faddevv Leverrier 63 Jacobi method for Symmetric Matrices 65 3 3 Managing Polynomials Defining and Storing Polynomials 67 Polynomial Arithmetic 69 Evaluating and Copying Polynomials 71 Polynomial Root Finders 72 Quartic Equation 72 General case Bairstow Method 74 3 4 Applications of Polynomials Equations for Curve Fitting programs 77 Polynomial Interpolation 78 Prime Factors Decomposition Totient function 80 Fitting data to Polynomials 82 Orthogonal Polynomial Fit 85 From
22. 3 5 7 37 211 362 880 123 456 2 6 3 643 41 088 000 c Angel Martin August 2013 Page 80 SandMatrix_4 Manual The programs are listed below There s no fancy algorithm for TOTNT it just counts the number of prime factors after doing the decomposition as a preliminary step 1 LBL TOTNT Euler s Totient Function 2 SF 04 3 XEQ 10 4 0 5 MSI 6 7 18 LBL PRMF 19 CF04 20 LBL10 21 PRME 22 2 23 E3 E 24 MATDIM 25 CLX 26 MSUA 27 RDN 28 CFOO 29 INT 30 ABS 31 PRIME 32 SFOO 33 MSR 34 X 1 35 GTOO1 36 FS C 00 37 GTOO1 38 stool 39 ST L 40 LASTX 41 LBL 05 42 E 43 STOO0 44 RDN 45 LBL 00 46 RCLO1 47 X lt gt Y 48 PRIME 49 SFOO0 50 XHY 51 GTOO2 52 ISG 00 53 NOP 54 FS C00 flag case get all Prime Factors sets pointer to 1 1 argument to x get element invert it sign change add 1 multiply end of row loop back refesh display done Prime Factors flag case 1 002 Create Matrix sets pointer to 1 1 argument to x default not prime condition x to avoid errors is it prime FIRST PF found Store this PF is PF 1 yes leave the boat Was it Prime if Prime we re done Store PF for comparisons divide number by PF Reduced number reset counter recall PF Reduced number is it prime PF found Compare this and old PF s skip over if different Same One Increase counter Was it Prime 55 GTO 03 skip if yes 56 ST L divide
23. CHS 4 ENTER 5 R S Note how in this case the function knows there s no more rows to add and also that negative values are easily input using the CHS key Upon completion the coefficients are stored in registers RO1 to ROS The last step is executing MPOL itself To do that we place the matrix name in Alpha and the polynomial control word in X then call MPOL The resulting P A is stored in a new matrix named P also located in an XM file therefore A is not overwritten Note however that this will overwrite P if it already exists In this case we have 3548 1887 4705 P A 3727 1987 4962 2539 1351 3385 c ngel Martin August 2013 Page 15 SandMatrix 4 Manual The result matrix name is placed in ALPHA when the execution ends so you can directly use any matrix editor routine like OMR to review its elements Note how OMR w display integer values without any zeros after the decimal point regardless of the current FIX settings Set flag 21 to stop the display of each individual element In addition to the result matrix P A MPOL also requires an auxiliary matrix for intermediate calculations The matrix file is temporarily created during the execution for this purpose and deleted upon completion of the program While this is transparent to the user you may want to remember this fact due to the extended memory needed to allow for it with a total of 3 x n 2 2 registers used i
24. CLFL cannot be used because it also clears the header register it was meant for Data files Use it safely for matrices in main and x memory MSORT uses an auxiliary matrix in main memory RO where RGSORT from the SandMath is applied to then data are copied back to the original matrix It also checks for available registers adjusting the calculator SIZE if necessary The contents of those n x m 1 data registers will be lost 1 LBL MSORT MName in Alpha 1 LBL MZERO MNAME in Alpha 2 SIZE current SIZE 2 DIMI get dimension 3 MSZE matrix size 3 SF 25 4 E 4 PURFL purge file 5 plus one 5 FCC 75 Was in main mem 6 M gt is it larger 6 GTO 01 jump over T PSIZE yes adjust size T MATDIM re create file 8 IM prepare Alpha string 8 RTN done 9 MAT make matrix RO equal 10 MSZE its size again ANUM get first reg from title 11 E3 E prepare control word 11 ENTERA copy in reg 12 RGSORT sort registers 12 MSZE get matrix size 13 ASWAp swap alpha 13 add to first reg 14 CLST prepare pointers 14 E3 3 prepare index format 15 MMOVE move all elements 15 add to first reg 16 MNAME recall original name 16 CLRGX clear registers 17 END done 17 END done has a new MCODE implementation in this revision directly reading the matrix header register Its funcionallity is equivalent to FLSI ZE for matrices stored in X mem but not so for matrices stored in main memory MSZE Header dll MSZE Header
25. CLRF12 B660 OF8 READ 3 X 070 N CALL 215 PNC XQ Build Msg all cases 212 i O B667 980 C N ALL B668 137C RCR 12 B669 121C PT 2 B66A bio LD PT O B66B l2DO LD PT B Es WRIT 15 e write it in display 9 bit 355 PNC XQ blank space to LCD 03C gt 0FD5 DSPL20 33D Input List in Alpha start anew no commas yet start anew no digits yet row number in BCD format move the MSB to C 0 add colon to digit 112 gt 44CF ALIST Not such a big deal you keep saying Well let s have a look at the remaining part in the Libary 4 c ngel Martin August 2013 Page 90 SandMatrix_4 Manual oe 1 ALIST 44cD DE 2 ALIST 44ce ME 3 ALIST 115 4 ALIST 038 5 ALIST 44D1 3E3 6 ALIST DOC 7 ALIST 093 8 ALIST 44D4 OBE __ 9 ALIST 44D5 130 10 ALIST l003 11 ALIST 12 ALIST 44D8 3E8 13 ALIST 44D9 348 14 ALIST TOALPH 15 ALIST 44DB 058 16 ALIST 44DC 149 17 ALIST 44DD 024 183 ALIST 44DE 051 19 ALIST 44DF 0B4 20 ALIST GOBACK 44E0 042 21 ALIST AAE1 058 22 ALUST 44E2 3D9 23 ALIST 44E3 01C 24 ALUST ANCHOR1 44E4 35B 25 ALIST FES 28C 26 ALUST 27 AUST 44E7 18C 28 ALIST 44E8 3E7 29 ALIST 188 30 ALIST 10D 31 ALIST 32 ALIST ANCHOR2 44EC 373 33 ALIST FED OBO 34 ALIST 44EE 106 35 ALIST 44EF 4130 36 ALIST AAFO 030 37 ALIST 44F1 366 38 ALIST 44F2 O04F 39 ALIST 44F3 3AC 40 ALIST ANCHOR1 444 1383 41 ALIST AAFS 0C4 42 ALIST 44F6 184 43 ALIST 44F7
26. Cartesian coordinate system It helps to think of such a vector as the tip of an arrow whose tail is at the origin of the coordinate system In this case the condition u is parallel to v means that the two arrows lie on the same straight line and may differ only in length and direction along that line If we multiply any square matrix A with n rows and n columns by such a vector v the result will be another vector w A v also with n rows and one column That is vy uy Ara Ai as Ain vy Uo uo Az1 Ags A Aan Us is mapped tof Un Wy A nl An A Ki Un c ngel Martin August 2013 Page 57 SandMatrix 4 Manual where for each index i Ti wy Ait A ave m 2 Aaa y Aat j 1 In general if v is not all zeros the vectors v and A v will not be parallel When they are parallel that is when there is some real number A such that A v A v we say that v is an eigenvector of A In that case the scale factor A is said to be the eigenvalue corresponding to that eigenvector In particular multiplication by a 3x3 matrix A may change both the direction and the magnitude of an arrow v in three dimensional space However if v is an eigenvector of A with eigenvalue A the operation may only change its length and either keep its direction or flip it make the arrow point in the exact opposite direction Specifically the length of the arrow will increase if A gt 1 remain the same if A 1 and decrease it i
27. ENTER 16 59 ENTER 17 MATDIM auxiliary matrix 60 E to be used as divisor 18 MIDN 61 19 ARCL 01 62 CHSYX 20 FS 01 LN 63 LBL 04 21 ASWAP yes swap names 64 A 22 EA 65 MAT divide by scalar 23 FS 01 LN 66 ABSP remove X 24 MAT 67 i cido ah prepare new string 25 FC 01 exp 68 MAT safekeeping copy 26 MAT 69 E 27 a 70 ST 02 increase term index 28 FNRM initial norm 71 sia 29 STO 00 store in ROO 72 FNRM new frobenius norm 30 FC 01 exp 73 X lt gt 00 swao with old norm 31 CLA 74 RCL 00 recall new again 32 ARCL 01 75 X Y are the different 33 FC 01 exp 76 GTO 02 yes keep at it 34 GTO 04 77 ARCL 01 no we re done 35 MAT 78 MAT 36 CLAC 79 PURFL purges ABSP 80 P 81 PURFL purges P 39 82 ASWAP 40 CLST 83 PURFL purges 41 MMOVE 84 MNAME recalls name to Alpha 42 2 85 END 43 STO 02 Remarks The program is relatively short but hefty in data requirements three auxiliary matrices are created and used during the calculations meaning that the total numbers of registers needed including the original matrix is 4 x dim A Note also that the convergence is based on equal Frobenius norms of two consecutive iterations and that the comparison is made using the full 9 decimal digits see instruction X Y in line 75 A rounded comparison would result in shorter execution times but it wouldn t be as accurate As usual these routines will result in ALPHA DATA if the matrix is in LU decomposed form
28. Integrate ROM the Polynomial ROM etc The solution to this riddle came only with the latest revision of the SandMath 3x3 which added a third bank with Solve and Integrate plus an important consolidation of functions in its auxiliary FAT This really cleared things off for the SandMatrix in that IIa a the SandMath itself for a total of only 8k effective footprint needed additionally since the Library 4 is located in the otherwise reserved page 4 So there you have it the SandMatrix more or less replaces all previous versions of the Advanced Matrix ROM the Matrix ROM and the Polynomial ROM not counting the one co produced w JM Baillard Also in this regard it s worth mentioning that the SandMatrix is totally independent from the JMB_ Matrix ROM which doesnt use the Advantage function set at all c ngel Martin August 2013 Page 5 SandMatrix 4 Manual 1 2 The many names of Dr Who The SandMatrix is the last incarnation of a series of different modules previously released that also dealt with Matrix and Polynomial algebra Some of them were based on the Advantage itself combining the matrix functions with other applications and thus followed the same bank switching implementation two pages with two banks in the upper page The differences amongst them were about what else beyond the matrix set they included once you removed the less notorious content of the Advantage
29. Martin August 2013 Page 38 SandMatrix_4 Manual lt a They are very much equivalent to MEDIT in many aspects although the symbo is used in the prompts They are slightly faster and offer the added convenient feature that for integer element values the zeros after the decimal point are not shown in the prompt regardless of the current display settings FIX or otherwise This makes for a clearer UI The program listing is shown below note how the different entry points set the appropriate subset of user flags and that they all share the main section for tha actual element input and review 1 LBL OMR 33 MSIJA set pointer to row col 2 0 clears FO F7 34 LBL 00 3 GTO 05 35 a element symbol 4 LBL OMC 36 MRIJ recall index sets F1 37 MP prompt index 38 MR recal value 39 FS 04 LU decomposed sets FO 40 GTO XX synthetic jump 41 INT integer 42 AINT yes append IP sets FO amp F1 43 FRC fractional 44 RAX lt yes append all 13 X lt gt F 45 FC 00 view only 14 LU is LU decomposed 46 AVIEW yes show it 15 SF 04 yes flag this fact 47 FC 00 view only 16 0 48 GTO02 yes skip editing 17 MSIJA resets pointer to 1 1 49 J append 18 GTO 00 go to first element 50 PROMPT show current value 19 LBL OXC 51 MS store new value 20 El sets F1 amp F3 52 LBL 02 53 FC 01 by column N 54 J yes next column sets F3 55 FS 01 by row 56 I yes increase row 57 El F10 is LU decomposed 58 FS 03
30. OP1 in Alpha OP1 in Alpha OP1 in Alpha Col in X OP1 in Alpha Row in X OP1 in Alpha OP1 in Alpha OP1 in Alpha none Cntl word in Z guesses in Y X Under prgm control Cntl word in X Under prgm control Matrix in XMEM Prompts Matrix Elements Under prgm control Under prgm control Driver for PSUM w CF 01 Driver for PSUM w SF 01 Driver for PPRD Rows swapped skip line if false element in X pointer to ij Row Norm in X sums of rows in RES matrix element sum in X element absolute sum in X Matrix replaced w transposed column k changed Edits Matrix Edits Complex matrix Prompts for element Displays Not Square Prompts for Row j 00i in X 0Oj in LastX comparison skip if False Inputs elements by columns Inputs elements by rows Yes No Do it true Matrix replaced by its root Matrix replaced by M M Copies matrix A into B Under prgm control Makes all elements x Sum of diagonal products Matrix replaced by exp M Element pointer if found Makes it Identity Matrix A B B A Matrix replaced by LN M Matrix replaced by M 4INT x Matrix redimensioned Matrix replaced by SQRT M Matrix Elements sorted Matrix size in X Trace in x All elements zeroed Shows elements by columns Shows elements by rows Shows Col elements Shows Row elements Prompts for complete Rows Diagonal elements 1 2 aij aji in X Displays 2 ak X k shows results Characteristic Pol Coeffs Deletes ak lt
31. PMTP function seen before just pretending the vector components are analogous to polynomial coefficients which is irrelevant to the actual workings of PMTP 1 004 XEQ PMTP gt R1 _ we type 2 ENTER 3 ENTER 7 ENTER 1 R S 6 009 XEQ PMTP gt R6 _ we type 3 ENTER 1 ENTER 4 ENTER 6 R S Re entering the control codes in X and Y we execute the function which returns XEQ DOTN gt 43 see table below for all the available data STACK INPUTS OUTPUTS Results o wp 46 52626239 oy Jpuj 7 874007874 MEA Y bbb eee U 7 937253933 bbb eee V 43 000000 j cos cos y A good example of Jean Marc s very complete and economical programming Needless to say it executes at blazing light speed as you would expect from an MCODE routine like this The alternative Vectors as Matrices V V performs the same tasks n dimensional vector dot product but using a different approach treating the vectors as column matrices it simply uses M M to calculate the resuilt multiplying the first operand vector by the transpose of the second operand vector All data input output are driven under program contol The execution time is longer than DOTN trading so convenience for speed To appreciate the workings of V V you need to consider that it transposes V2 before doing the multiplication and that it calculates the Frobenius norms of each matrix on the fly to obtain
32. R S a2 5 0000 R S a3 7 0867E 8 R S a4 20 0000 R S a5 2 6188E 7 R S a6 16 0000 So disregarding the very small coefficients due to rounding errors the undisguised polynomial is P x cos 5 arccos x 5 x 20 x 3 16 x45 You might want to execute now CAT 4 or EMDIR to see that the matrices used are still available so that you can redisplay the coefficients solve for a new set of y values or use the polynomial for interpolation etc CAT 4 MX M036 the system matrix is 6x6 36 elements MY M006 the coeff matrix is 6x1 6 elementss 554 0000 this value varies with your configuration c ngel Martin August 2013 Page 84 SandMatrix_4 Manual 4 4 5 Orthogonal Polynomial Fit OPFIT Orthogonal polynomials are a very advantageous method for polynomial regression Not only it allows for a more progressive approach but also the accuracy of the values so obtained is typically better This program employs this method even if it doesn t calculate any orthogonal polynomials explicitely Given m value pairs xi yi and a maximum degree to explore n this program calculates the n n 3 2 polynomial coefficients of the corresponding n polynomials of degrees 1 2 3 n that best fit the given data therefore equivalent to the least squares method It also obtains the determination coefficients and typical errors for each degree The method followed uses the construct Y
33. The table below illustrates this showing the dependencies and choices made in all the predecessors of the SandMatrix Size Dependency Requires MATRIX 4k gt Advantage n a POLYN_4k MATRIX 4L4 LibH4 gt Advantage POLYN_4k Includes SOLVE INTEG a POLYN_4L4 Lib 4 Includes SOLVE INTEG i RVE FIT Adv_Matrix4_II ne Lib 4 Includes CU SIROM for EIGEN only We sure have a much simpler situation now glad to say we left all those behind What isn t included When compared to the original Advantage Pac the following functionality areas are not included in the SandMatrix but in other dedicated modules and in a superior implementation if 1 may add as shown in the table below Section InModue AlsoAvailablein_ Comments HP 412 DedicatedskROM Vectors Coordinates Vector Calculator ROM Dedicated 4kROM_ Note Make sure that revision H or higher of the Library 4 module is installed c Angel Martin August 2013 Page 6 O CON DUM Sh 0 N PR SandMatrix_4 Manual Function index at a glance And without further ado here s the list of functions included in the module SNDMTRX 4 ABSP AIP ASWAP CLAC DOTN EQT SQR MATRX MPOL ST lt gt A Viv 3DV Alpha Back Space Appends integer part Alpha Swap CLA from Comma N dimensional Dot product Displays Curve Equation Tests for Square matrices Easy Matrix Program Matrix polynomial Swaps Alpha Stack 3 dim
34. X and mmm nnn Y for the first matrix and element 1 001 Z for the second matrix thus defining two entire matrices For example in a 4 x 5 matrix Y Register Pointer Value 0 000 4 005 3 000 3 005 0 003 4 003 c ngel Martin August 2013 Page 34 SandMatrix_4 Manual Miscellaneous Arithmetic Functions Maxima and Minima Description Imp Input Output Outp ut ee eee ea sets element pointer to it Outputs element value to X reg oe EEA T Sines Swine Sets element pointer to it Outputs element value to X reg element point to it Outputs element value to X reg Soa Slee lO th column Sets element pointer to it Outputs element value to X reg e e a A EAT row Sets element pointer to it Outputs element value to X reg Miscellaneous Arithmetic functions Norms and Sums a ae Input Output CNRM Column Norm Finds the largest sum Matrix name in Alpha of the absolute values of the elements Outputs colum norm to X reg in each colum of matrix Sets pointer to first element of colum no oo root of the sum Of the squares of all Outputs frobenius norm into X reg elements in matrix 12 Row Norm Finds the largest sum of Matrix name in Alpha the absolute values of the elements in Outputs row norm to X reg each row of matrix Sets pointer to first element of row SUM Sums all elements in matrix Matrix name in Alpha Outputs the sum to X reg CSS aa o in matrix Outputs the sum to X reg stores t
35. a So oe se So BE me Ms amp D A E de a Tan A ADA o a e anua a ea ms e e S82 eee ose ERAS PERES LA _ i eg eo oo o ao c m 000 A A A XA RA A A S e a Es Us Es e o cd A TEE RS ES ee z m E a al r o 2 8 8s 8 8s e SsS8 5 Al a d Ti Ds Ta Pe Cig tati ta to LL 232 Al Al oan O 5 E 209E Sar m gt 19 Us Dc soon nen o a Sa am P Ur ro or amp e ba 94 i e 55 0 00 2 Fa Ta T Fa Fa a a ya a Ll sl See ee gt ll bi Fig Fe fo Ca Es Es TR e o aa So e eo s sd S 58 END a Y S5 BB a a E a Me s a S sa l L ir a o e aa S S p e e e as a 28 se _ SSS gse Ge ee ee 05 15 55 O DO rey eS m Ye 252 Sa85 Page 93 7 c Angel Martin August 2013
36. a complicated affair but it has been automated just follow the process carefully It makes extensive use of the polynomial arithmetic routines PPRD and PDI V Also the polynomial entry routine PEDI T is called several times The program prompts for the number of factors in the denominator as well as for their degrees and multiplicities It also prompts for the coefficients of the numerator polynomial and of each factor polynomial in the denominator so you don t need to store those values manually prior to executing PFE Data output is not automated therefore you d need to interpret the control words returned in stack registers Some guidelines will follow in the examples Examplel Calculate the partial fraction decomposition for R x below R x P xV Q x 6x 19 xf 20 x 7x7 7x4 10 2x x4 1 x 2 7 Keystrokes Display Result XEQ PFE DEN Input number of factors 2 R S NUM inputs degree of numerator 5 R S d aK X K Reminder of convention a5 coefficients data entry 6 R S a4 19 CHS R S a3 20 R S a2 7 CHS R S al 7 R S a0 10 R S Q1 Input degree of Q1 in den 2 R S D aK X K Reminder of convention a2 2 R S al 1 R S a0 1 R S Q2 1 R S D akK X K Reminder of convention al 1 R S a0 2 CHS R S XP u time to enter the multiplicities now al e
37. arrays You do not need to specify a file type it will automatically be given one unique to matrices Use the Alpha register to specify matrix names When specifying more than one name as parameters for certain functions separate them with commas Dimensioning a Matrix Specify the dimensions of a new matrix as mmm nnn where m is the number of rows and n is the number of columns You can drop leading zeros for m and trailing zeros for n For a complex matrix specify mmm nnn as twice the number of rows and twice the number of columns Refer to Working with Complex Matrices A zero part defaults to a 1 so O is equivalent to 1 001 3 to 3 00 1 and 023 to 1 023 l 2 3 L 2 A 45 6 4 55 6 7 mnnn nnn 2 003 mmm nna 4 004 c ngel Martin August 2013 Page 20 SandMatrix_4 Manual e MATDI M Dimensions a new matrix or redimensions an existing one to the given dimensions Returns the name of the current matrix to the Alpha register Returns the dimensions mmm nnn of the matrix specified in the Alpha register to the X register A blank Alpha register specifies the current matrix How a Matrix Is Stored The elements of a matrix are stored in memory in order from left to right along each row from the first row to the last Each element occupies one data storage register A complex number requires four registers to store its parts Memory Space A matrix in main memory occupies m x n 1 datastor
38. at the end which indicates the value cannot be changed from the program In edit mode You can control wether PVIEW stops after each prompt or does the complete listing without stopping by setting or clearing the user flag 21 Note also that if the coefficient is an integer value it will not display the zeroes after the decimal point in both editi and review modes A faster alternative for data entry is the polynomial prompt This one does for polynomials what PMTM did for matrices the data entry is done as a list in Alpha containing the values of all coefficients at once Obviously this is limited by the total length available in the Alpha register 24 characters including the blank spaces that separate each entry and the minus signs for negative values The two leftmost characters in the prompt indicate the first data register used to sore the coefficients not the row as in the Matrix case These characters are not part of the final list and therefore aren t included in the total count Another restriction of is that values cannot be expressed in exponential form using EEX which key is ignored during the process You can use negative and decimal values as the CHS and radix keys are active Obviously the back arrow key is always active to correct wrong entries 27 2 SF 08 flags mode 28 RCL IND Y append current value d 3 ENTER copies cntl word to Y g 29 has fractional part 4 I
39. by row yes flag this fact 59 DSE X yes F9 60 FC IND X end of matrix row 61 GTO 00 no next element 62 MNAME yes recall Mname row 63 END and end yes transpose Other pointer utilities included are listed in the table below they are used in many of the FOCAL programs described in the following sections __ Function Description Imput Output E AMROW Prompts the list and controls input Element values as Alpha List S Swaps iii and jjj in X iii jjj in X reg also does E3 for integers Index swapped to jjj iii oar le ee O YES NO do if true Ep peremees PRES e YES NO do if True epee TREERE e eea and sets element pointer to it Outputs the pointer iii jjj to X reg c ngel Martin August 2013 Page 39 SandMatrix 4 Manual 3 2 New Matrix Math functions 3 3 1 Utility housekeeping functions rounding the capabilities This group comes very handy for the handling and management of intermediate steps required as part of more complex algorithms As a rule the functions work for matrices stored either in main memory or in X memory Only and create new matrices all other functions expect them already dimensioned Function Input Output Description B A Both must exist Under program control Creates both matrices on the fly Makes aij x i 1 2 m j 1 2 n Makes all matrix elements equal to x e cc A Returns pointer to X and set to element 5 ME Makes identity Matrix Matri
40. c Angel Martin August 2013 Page 85 SandMatrix_4 Manual 4 4 6 From Poles to Zeros and back These two programs complete the applications section The first one calculates the zeros of a polynomial expressed as a partial expansion of factors as would typically be the case when working with transfer functions in control theory The second program builds the partial fraction expansion for a polynomial given it its standard or natural form Input Output 1 POLZER Zeros of transfer functions Under program control 2 PFE Partial Fraction Expansion Under program control This program calculates the polynomial coefficients and roots of expressions such as P x 2 1 x pi 1 i 1 2 n Which will be transformed into P x aix i i 0 1 n 1 The coefficients are obtained using the following formulae a n 1 n a n 2 n 1 2 pi a n 3 n 2 2 2 pi pj a n 4 n 3 2 2 pi pj pk a n 5 n 4 2 2 2 pi pj pk pl a n 6 n 5 2 2 2 2 pi pj pk pl pm in general the n th coefficient would require the calculation of n dimensional product sums However the program POLZER is limited to expressions up to 7 poles max resulting in 6 zeroes Example To study the stability of the transfer function below calculate its roots G s 1 s 1 s 1 1 s 2 1 s 3 1 s 4 Keystrokes Display XEQ POLZER FPOL 5 R S P 1 0 R S P 2 1 R S P 3 2 R S P
41. categories or were added at latest stages of the development 2 1 Alpha String Management The use of the ALPHA register for Input Output certainly isn t new in the 41 platform but the utilization by the Matrix functions effectively turned it into an abstraction layer for programming therefore the importance of auxiliary utilities like these Some of these functions are also included in the AMC_OSX Module yet it appeared convenient not to add it as another dependency even if it s just a 4k footprint for its 3 banks so here they are as well Function Description Emput gt _ gt o 2 AIP Appends integer part x in X ASWAP Alpha Swap A B in Alpha aa a OOOO 5 EQT_ DisplaysCurve Equation Eq finR00 1 16 gt Z o Z o o 6 ST lt gt A Exchanges Alpha and Stack Values in Stack and Alpha registers ABSP deletes the rightmost character in ALPHA equivalent to back space in manual mode AIP was HP s answer to the need to append just the integer part of the number in X to Alpha not changing the FIX and radix settings Note also that AIP appends the absolute value of the number which is not the case with ARCLI or Al NT from the CCD and AMC_OS X modules ASWAP handles comma separated strings exchanging the strings placed left and right of the first comma found in Alpha Very handy to manage all those operations that have an input and output matrix names defined in ALPHA separated by comma CLAC delete
42. doing it element to element would be a long and impractical method The alternative is to use the matrix Frobenius norm as a surrogate criterion assuming that for very similar matrices they ll be equal when they have the same norm There s no saying to the execution time or whether the calculator numeric range will be exceeded in the attempt so you can expect several iterations until it converges The matrix norm will be displayed after each iteration so you ll have an indication of the progress made comparing two consecutive values Logarithm of a Matrix In mathematics a logarithm of a matrix is another matrix such that the matrix exponential of the latter matrix equals the original matrix It is thus a generalization of the scalar logarithm and in some sense an inverse function of the matrix exponential Not all matrices have a logarithm and those matrices that do have a logarithm may have more than one logarithm Furthermore many real matrices only have complex logarithms making it so even more challenging The SandMatrix uses the following algorithm If ILA I lt 1 the logarithm of a n x n matrix A is defined by the series expansion La A A I A 1I 2 A 1Y 3 CATA where I is the identity matrix Example 1 Calculate the exponential of the matrix A given below and then calculate its logarithm to see how the result matrix compares to the original i 2 3 A 0 1 2 1 3 2 The first part of the a
43. elements 2 DIM current dimension 3 o 3 ENTERA push it to Y MISLA set pointer to 1 1 4 INT n 5 E element value 5 MATO row matrix nx I 6 LBL 00 6 E 7 MSC store and increase l 7 MECON all ones B FC 09 end of row E Xx Y n g J yes next row 9 n 10 FC 10 end of matrix 10 LAST n 11 GTO no next element 11 gt 0 00n 12 END yes done 12 n 1 00n 13 MATDIM shorter and faster even if more pedestrian 14 TRAPS 15 Mo gt original nxn 16 MATDIM bach to shape 17 END done Of all these perhaps only needs further explanation Contrary to MATDI M a proper re dimensioning should respect the elements in the re dimensioned matrix that held the same position in the original one does this deleting the discarded elements when the redimensioned sub matrix is smaller than the original and completing the new onew with zeroes wihen it is bigger super matrix It always starts with a11 no random origin is possible MNAME in Alpha 16 X lt gt Y min j1 j2 2 DIM get dimension 17 RCL Z 3 X lt gt Y new dimension to X 18 INT min I 4 ASTO T temporary safekeep 19 min I min j 5 paa add tilde 20 0 6 MATDIM create new matrix 21 STO Z prepare pointers 7 CLA 22 ASTO T temporary safekeep 8 ARCL T MNAME 23 9 X gt Y 24 ARCL T MNAME 10 X lt gt Y min i1 i2 25 e e prepare Alpha string 11 STO Z keep in Z 26 MMOVE copy elements 12 FRC 27 PURFL purge original file 13 X lt gt Y 28 MNAME recall name to Alpha 14 FRC 29 END done 15 X gt Y
44. however now requires you to first create the matrix and input its elements Algorithmically it still uses the same modification of the Leverrier Faddeev method to determine the coefficients of the characteristic equation of the n x n matrix which roots are the eigenvalues of the matrix It also employes the matrix trace in the process The coefficients are calculated using the iterations b1 tr B1 with B1 the original matrix and bk tr Bk k with Bk A Bk 1 bk 1 I k 2 n The program works for orders n between 3 and 14 The case n 2 has a trivial solution given by b2 1 b1 tr A and b0 det A therefore doesn t need to be included Example Obtain the characteristic polynomial for the matrix A given below 1 0 69 0 28 A 0 69 1 0 18 0 28 0 18 1 Keystrokes Displa Result ALPHA LPHA AA ALPHA current X reg Matrix name in Alpha 3 003 XEQ MATDI M 3 003 Creates matrix in X Mem XEQ IMR al l Prompts for data also 1 R S al 2 showing current values 0 69 CHS R S al 3 0 28 R S a2 1 0 69 CHS R S a2 2 1 R S a2 3 0 18 R S a3 1 0 28 R S a3 2 0 18 R S a3 3 2 Last element 1 R S 1 000 XEQ CHRPOL RUNNING scrolls in the display then D akK X K Reminder of convention set F21 a3 1 000000 Coefficient of x 3 if you want AVIEW a2 3 000000 Coefficient
45. indices before the pointer can be used again Existing matrices in extended memory cannot be redimensioned to completely fill extended memory The maximum allowable size of a redimensioned matrix is one register less than the currently available extended memory A new matrix can however be dimensioned to completely fill available extended memory Using the Matrix Editors There are two matrix editors MEDIT for real matrices and CMEDIT for complex matrices They are otherwise quite similar The matrix editors are used for three purposes c ngel Martin August 2013 Page 21 SandMatrix 4 Manual e Entering new values into the elements of a matrix e Reviewing and changing editing the elements of a matrix either in order or by random access of specific elements e Viewing without being able to change the elements of a matrix flag 08 set When you execute MEDIT or CMEDIT the editor displays element 1 1 of the matrix specified in the Alpha register or of the current matrix if the Alpha register is empty Pressing R S steps the display through the elements for a complex matrix each part of the complex element is shown separately Function Display Function Display MEDIT 1 1 1 0000 CMEDIT RE 1 1 1 0000 R S 1 2 2 0000 R S IM 1 1 1 00007 R S RE 1 2 2 0000 R S X register R S X register The at the end of the display line indicates that you can change that value In effect you are being asked w
46. lt gt J swaps bbb and eee i 30 ARCL X yes append as is 5 E i 31 integer i 6 d 32 yes append IP only if 7 SIZE current size ij 33 FC 00 editable rg X lt gt Y 34 AVIEW no show already f 9 X gt Y not enough d 35 FC 08 editable g 10 PSIZE adjust size 36 GTO 02 no next coeff 11 RDN d 12 RDN cntl word to X reg J append g skip over d 39 CF 22 reset data entry flag o 40 PROMPT flags mode d 41 FC 22 value entered 42 GTO 02 no next coeff 17 ADV POLYN shows convention d 43 STO IND Z yes store it i 18 PSE RDN discard entry d 19 ENTER copies cntl word to Y 45 LBL 02 d 20 polyn degree 46 DSE X decrement counter 21 X lt gt Y cntl word to X reg 47 NOP d 22 STO L saves it in L d 48 ISG Y increment register d 23 X lt gt Y degree to X reg d 49 GTO 01 next register 24 LBL 01 50 LASTX get control word 25 a 54 END done d 26 AIP append index c Angel Martin August 2013 Page 68 SandMatrix_4 Manual 4 2 2 Polynomial Arithmetic PDIV The arithmetic functions provide convenient functionality for the basic operations addition subtraction multiplication and eucliedean division A distinction is made between the three base routines PSUM PPRD and PDIV written by JM Baillard and the four user friendly drivers that automate the element data entry and work out all the details behind the scenes For the first group beside the element data entry the control words for each opera
47. matrix Name in Alpha kkk IIl in X reg 2 R lt gt R Exchange Rows k and in a matrix Name in Alpha kkk IIl in X reg 3 MMOVE MatrixMove Names in Alpha Pointers in stack 14 MSWAP Matrix Swap Names in Alpha Pointers in stack MMOVE and MSWAP Copies or Exchanges the submatrix defined by pointers in the source matrix to the area defined by one pointer in the target matrix The inputs require both matrix names in Alpha separated by a comma plus the pointers in the stack as follows When executing MMOVE and MSWAP if A and B are the same matrix and the source submatrix overlaps the target submatrix the elements are processed in the following order reverse column order last to first and reverse element order last to first within each column MSWAP MIGO Source matrix 4 Target matrix 8 When an input of the form iii jjj is expected in the X register a zero value for either the i part or the j part is interpreted as 1 Zero alone equals 1 001 This is true for the iii ijj values that MMOVE and MSWAP expect in the X and Z registers but not for the pointer value in the Y register For the Y register input a zero value for the i part is interpreted as m the last row while a zero value for the j part is interpreted as n the last column This convention facilitates easy copying or exchanging of entire matrices because simply by clearing the stack CLST or entering three zeros you specify the elements 1 001
48. number by PF 57 LASTX Reduced number 58 GTO 00 loop back Store Exponent 60 RCL 00 recover PF 61 MSR store in matrix 62 GTO01 gt next factor New PF found 64 STO 01 Store for comparisons 65 RCL 00 previous exponent 66 MSR Store Old PF Exponent 67 RDN 68 ST L divide number by PF 69 LASTX Reduced number 70 DIM 71 X lt gt Z Bring the new PF back 72 MSR store new PF 73 FS C 00 Was it Prime 74 GTO 01 Bail Out we re done 75 X lt gt Y Bring the number back 76 GTO 05 Start Over 77 LBL PF gt X Rebuild number 78 SF 04 flag case 79 PRMF matrix name 80 SF 10 fake condition 81 LBL 01 PF Completed 82 E 1 83 FC 10 end of matrix 84 MSR store it as last exp 85 STO 00 initial value 86 MSIJA sets pointer to 1 1 87 CLA Clean Slate 88 Rebuild the number get prime factor if not totient case add t to Alpha get multiplicity if not totient and or if it is one skip adding to Alpha otherwise put symbol and add it to the string 98 PF Exp Rebuilding the number End of Array yes leave the boat if not totient case append symbol next PF 106 107 RCL 00 final result 108 FC 04 if not totient case 109 AVIEW Show the construct 110 END done c Angel Martin August 2013 Page 81 SandMatrix 4 Manual 4 4 4 Polynomial Fitting POLFIT gt The next program is taken from Valent n Albillo article Long Live the Advantage ROM showcasing the matrix functions included in i
49. of x 2 to stop each time al 2 413100 Coefficient of x a0 0 343548 First coef independent term RUNNING X 0 180390390 R S X 1 121568609 X 1 698238062 Scrolls in the display then First eigenvalue Second eigenvalue Third and last c Angel Martin August 2013 Page 63 SandMatrix 4 Manual See the program code below in its entire splendor realizing that it may be the last program written using Advantage Matrix functions Remarks Two auxiliary matrices are used but the original matrix is left unaltered The first part of the program up to line 60 calculates the coefficients of the characteristic polynomial and displays them for informational purposes It then transfers the execution to the root finder routines Note that for cases n 3 and n 4 we take advantage of the dedicated functions CROOT in the SandMath and RTSN QUART which result in much faster execution than the general case using RTSN MNAME in Alpha 53 E3 E 1 001 2 DIM n 00n 54 1 00 n 1 cnt l word 3 l J 55 4 ADV MATRX 56 PURFL 5 ASTO 01 MNAME 57 Ape 6 CCD MATRIX shows RUNNING 58 PURFL 7 P 59 PVIEW for information 8 MAT B A 60 CCD MATRIX shows RUNNING 9 ASWAP 61 PDEG new destination 10 DIM n 00n 62 STO 00 as expected by RTSN 11 INT n 63 4 12 E 64 X gt Y n lt 4 13 n 1 65 GTO 04 yes particular case 14 MDET independent term 66 CLX no general case
50. p b n 1 2 clearly with both r and s depending on the p q values formally expressed as r r p q and s s p q The problem is thus obtaining the coefficients p q of such a quotient polynomial that would cancel the reminder i e that make r 0 and s 0 This is accomplished by using an iterative approach starting with some initial guesses for them p0 q0 iterating until there is no change in two consecutive values r pq r 0 or p q r s p q s 0 or s p q s Expressing it using their partial derivarives it results dp sr sp dq 6r dq r dq s p dq 3s 5q s Using the relationships 1 above we can formally obtain the partial derivatives using the coefficients of the original polynomial ai The problem will then be equivalent to solving a system of 2 linear equations with two unknowns dp and dq From equation 1 above it follows obi dp ci b i 1 p c i 1 q c i 2 i 2 3 n 2 dbi d5q c i 1 Making use of equation 2 to apply it for i n we have as final expression c n 1 dp cn dq b n 1 qcn dp c n 1 pcn dq b n 2 p b n 1 3 c ngel Martin August 2013 Page 74 SandMatrix_4 Manual Starting with p0 0 5 q0 0 5 as initial guesses we ll obtain dp and dq for each pair of values p q With them we adjust the previous guess so that the new corrected values for p and q are p p dp q q dq This will be repeated until the precision factor
51. program and the complex matrix editor CMEDIT recognjze a matrix as complex and treat its elements accordingly All other functions treat the real and imaginary parts of the complex elements as separate real elements How Complex Elements are represented In its internal representation a complex matrix has twice as many columns and twice as many rows as it normally would 100 200 The complex number 100 200i is stored as 200 100 i 2 1 2 x d The 2 x 1 complex matrix _ is stored as 3 4 3 d 4 3 There is one important exception to this scheme for the column matrix a vector in a system of simultaneous equations Solving Complex Simultaneous Equations The easiest way to work with complex matrices is to use the MATRX program It automatically dimensions input and output complex matrices However MSYS can solve more complicated systems of equations than MATRX can In addition a complex result matrix from the MATRX program cannot be used for many complex matrix operations outside of MATRX This is because MATRX will dimension a complex column matrix differently than 2m x 2 Instead it uses the dimensions 2m X 1 in which the real and imaginary parts of a number become successive elements in a single column c ngel Martin August 2013 Page 29 SandMatrix 4 Manual This form has the advantage of saving memory and speeding up opera tions The complex matrix editor and MSYS can also use this 2m X 1 form th
52. the angle The dot product is placed in a 1x1 matrix named V V in X Mem Here s the listing of the program that clearly shows all the housekeeping chores required to prepare the strings needed in ALPHA for the matrix functions as input Even if it s somehow slower and less efficient it s a good academic example of utilization of the standard matrix functions c Angel Martin August 2013 Page 17 SandMatrix 4 Manual 01 LBL V y 31 FNRM 02 FS 06 subroutine use f 32 l 03 GTO 00 yes skip data entry 33 V2 O04 SNDMTRX4 prompts ORDER 34 FNRM 05 STOP o 35 06 INT 36 ACOS 07 ne 37 XoY o8 MATDIM o 38 CO Veja 09 XEQ 05 V1 data input F 39 ARCLY 10 DIM 40 PROMPT show angle o 31 y2 41 RTN i MATDIM 42 LBLO5 XEQ 05 UN V2 data input 43 3 LBL 00 AA XoF 15 yxy a45 0 gt 16 CLX F 46 MSIJA position pointer 17 MATDIM 18 nyg f 19 TRNPS d 20 nj V2 V V d rod M M ij 22 ASHE 52 ARCLX 23 0 reg P 24 MSIJA position pointer 54 PROMPT id 25 MR recall element o 55 MS 2G ENTERA rg i 27 J 57 FC 10 reached the end d 28 ARCL X l 58 GTO 04 no loop back 29 PROMPT show result 59 MNAME 30 ae 60 END The usage of user flag 06 determines whether the program is used as a subroutine in which case the data entry is skipped This is more or less consistently done throughout the SandMatrix module and h
53. the inverse procedure of the more elementary operation of addition of rational fractions which produces a single rational fraction with a numerator and denominator usually of high degree The full decomposition pushes the reduction as far as it will go in other words the factorization of g is used as much as possible Thus the outcome of a full partial fraction expansion expresses that fraction as a sum of fractions where the denominator of each term is a power of an irreducible not factorable polynomial and the numerator is a polynomial of smaller degree than that irreducible polynomial To decrease the degree of the numerator directly the Euclidean division can be used but in fact if f already has lower degree than g this isn t helpful Implementation POLZER may be an old program but is a much more modern event written by JM Baillard and published at http hp41programs yolasite com part frac expan php Given a rational function R x P x Q x with Q x qi x JY wee dn x JP and gcd qi qj 1 foralli j this program returns the partial fraction expansion R x E x p1109 109 1 pax 19100 17 eee Pipi 41x Ao Paa X E a x 1 Prix E AOO PO eeeteeteeteteees Pnun X An X c Angel Martin August 2013 Page 87 SandMatrix 4 Manual where deg pix lt deg qi and E x is the quotient in the Euclidean division P x E x Q x p x and p x is the remainder Data entry is
54. the polynomial control word in X Note that they will be overwritten during the execution of the program It uses registers ROO to RO8 internally thus cannot be used to store your data For both programs the accuracy of the solutions and therefore their run times depends on the display settings BAIRS factorizes the polynomial p x ao X a X Ap 1 X a into quadratic factors and solves p x 0 n gt 1 If deg p is odd we have p x a0 x b 0 U X V1 X Um X Vm with m n 1 2 If deg p is even D X a0x u xv O U Xx EV2 O Um EV 5 With m n 2 The coefficients u and v are found by the Newton method for solving 2 simultaneous equations Then p is divided by x u x v and u 8 v are stored into R ee 1 amp Ree respectively The process is repeated until all quadratic factors are found Example 2 Solve x 6 x7 8 x 64 x 345 x7 590 x 312 0 Using to store the coefficients beginning in RO9 thus the control word is 9 015 Keystrokes Display Result 9 015 XEQ PMTP RO 1 ENTER CHS 6 ENTER 8 ENTER 64 ENTER CHS 345 ENTER 590 ENTER CHS 312 R S 9 015 XEQ BAI RS shows precisions factors The solutions are Z 4 000 and Z 2 000 Z 2 000 J3 000 and conjugate not shown Z 1 000 and Z 3 000 c Angel Martin August 2013 Page 76 SandMatrix_4 Manual 4 4 Extended Polynomial Applications A few related
55. topics in that polynomials are involved even if some programs don t make direct utilization of matrix functions Here too the SandMatrix complements the functionallity included in the SadnMath The table below summarizes them Description Input Output _ Function Equation Display Equation number in ROO 0 1 to 15 POLI NT Polynomial interpolation Under program control 3a PRMF 3b PF gt X 4 POLFIT Polynomial Fitting Prime Factors decomposition From prime factors to argument Argument in X reg Prime factors in matrix PRMF TOTNT Euler s Totient function Argument in X reg Under program control OPFIT Orthogonal Polynomial Fit Under program Control 6a POLZER From Poles to Zeroes Under program control PFE _ Partial Fractions Expansion Under program control 4 4 1 Displaying the Equations for Curve Fitting Programs As there was plenty of available space in the module I decided to include this routine to complement the Curve Fitting program in the SandMath CURVE The routine will write in Alpha the actual equation which reference number is in register ROO ranging from O to 15 as per the table below Linear Reciprocal Hyperbola Reciprocal Hyperbola Power Modified Power Root Exponential Logarithmic Linear Hyperbolic 10 2 Order Hyperbolic 11 Parabola 12 Linear Exponential 13 Normal 14 Log Normal 15 Cauchy WOANHDUARWNHFO Note that does not
56. wise this manual begs steals and borrows from many other sources in particular from the HP 41 Advantage Manual Not so from the CCD Manual but obviously that was how it all began with the excellent implementation of the Array Functions by W amp W GmbH Thanks to the following contributors must be given Jean Marc Baillard Valentin Albillo Eugenio Ubeda and Ulrich Deiters Original authors retain all copyrights and should be mentioned in writing by any party utilizing this material No commercial usage of any kind is allowed Screen captures taken from V41 Windows based emulator developed by Warren Furlow Its breakpoints capability and MCODE trace console are a godsend to programmers See www hp41 org Published under the GNU software licence agreement c Angel Martin August 2013 Page 2 SandMatrix_4 Manual Table of Contents Revision K 1 Introduction SandMatrix 4 Revision k 5 Logical next chapter after the SandMath 5 The many names of Dr Who 6 What isnt included 12 Function index at a glance 15 2 Lower Page Functions in Detail 2 1 SandMatrix 4 Group Alpha String Manipulation 10 Other functions in header section 11 The MATRX program 11 Matrix Polynomial 15 N dimensional Vector operations 17 3D Vectors mini calculator 18 2 2 Matrix 101 Setting up a matrix 20 How a matrix is stored Matrix Editors 21 How to Specify a matrix 22 Storing and Recalling Martrix Elements 24 Updated Matrix Editor 25 2
57. x dO PO x d1 P1 x dn Pn x where pO pl pn are the orthogonal polynomials corresponding to the entered data that satisfy the expression pi Pj 0 for every i j The advantage of this approach is a better accuracy as it avoids the resolution of the usual n linear systems frequently ill conditioned that arise in the least squares method Example To check the program we took the following 11 value pairs from the polynomial P x x 4 2x 3 3x 2 4x 5 ij 3 2 t o 2 2 3 4 5 6 7560 Yi 179 57 15 5 3 9 47 165 435 953 1839 Using the data above explore up to degree n 4 showing the correlation coefficients the D factors and the errors for each of the alternatives The results are all provided in the table below Degree n Corrlt r 2 Errors e 2 Determ d 2 Coefficients a0 9 140000E1 y i E A 3 295160E5 Ena 3 370000E2 a a0 1 486000E2 E i al 3 720000E1 R2 9 000134E 1 E2 3 294720E4 D2 4 000000E1 a2 4 000000E1 a0 1 700000E1 a1 7 200000E1 R3 9 821452E 1 E3 5 883429E3 D3 6 000000E0 a2 4 000000E0 a3 6 000000E0 a0 5 000000E0 a1 4 000000E0 E 7 E a2 3 000000E0 R4 1 000000E0 E4 0 000000E0 D4 1 000000E0 3 2 000000E0 a4 1 000000E0 Original author OPFIT was written bu Eugenio beda and published in the UPLE The version in the SandMatrix has only minimal changes made to it It is by far the longest program in the module
58. x th root of a Matrix Matrix Square Copy Matrix Driver for M M Constant Diagonal Product Sum Matrix Exponential Element finder Identity Matrix Matrix Lie Product Matrix Natural Log Matrix Power to X Matrix Redimension Matrix Square Root Sorts matrix elements Matriz Size Matrix Trace Zeroes a Matrix Output Matrix by Columns Output Matrix by Rows Output x th column Output x th row Prompts for Matrix Unitary Diagonal Sum of crossed products Section Header Bairstow Method Characteristic Polynomial Detele Tiny Coefficients Eigen Values by SOLVE Eigen values 3x3 Eigen values 3x3 Symmetrical Eigenvalues Orthogonal polynomial Fit Polynomial Addition Polynomial Substraction Polynomial Multiplication c Angel Martin August 2013 SandMatrix_4 Manual kkk Ill in X kkk Ill in X row in X OP1 in Alpha OP1 in Alpha OP1 RES in Alpha OP1 in Alpha OP1 in Alpha OP1 in Alpha value in Y kkk lll in X prompts for elements prompts for coeffs lii jjj in x none OP1 in Alpha row in x lii jjj in X iii jjj in X OP1 in Alpha OP1 in Alpha Mname in Alpha OP1 in Alpha xin X OP1 in Alpha OP1 RES in Alpha Driver for M M OP1 in Alpha xin X OP1 in Alpha OP1 in Alpha OP1 in Alpha xin X OP1 in Alpha OP1 OP2 RES in Alpha OP1 in Alpha OP1 in Alpha x in X OP1 in Alpha dim in X OP1 in Alpha OP1 in Alpha OP1 in Alpha OP1 in Alpha OP1 in Alpha
59. 15 DIM exit 16 INT of rows for M1 17 cresult matrix dimension 18 M matrix name M 19 MATDIM create matrix in X mem 20 J M1 M2 prepare Alpha string 21 2 done 22 AROT 23 M M matrix product 24 ASHF remove acratch 25 OMR output values 26 END done Note that in MATP I have chosen PMTM to enter the element data values therefore it s somehow limited by the same constraints described before ie total length in Alpha and no support for the EEX key c ngel Martin August 2013 Page 43 SandMatrix 4 Manual 3 2 2 New Math functions Completing the core function set The next group incudes advanced application areas in core matrix math _ Function _ Description A A e A exp 1 x Ln A The result matrix replaces the input A A 2 A A The result matrix replaces the input g Input Output MDPS 2 aii aii 1 i 1 2 n Output is result in X reg A exp A The result matrix replaces the input C AB BA Result matrix C must be different A Ln A The result matrix replaces the input e a RE A ASx The result matrix replaces the input A sqrt A The result matrix replaces the input 17 MTRACE Calculates the Trace of a Square Matrix name in Alpha Matrix Output is put into W reg Trace 2 aii i 1 2 m akj akj akk j 1 1 n All row elements divided by akk SCEP 2 aij aji Output is put in X reg Formulae and algorithms used The algorithms us
60. 2 4 ENTER O 8 6 R S With LINKS in Alpha we type XEQ PMTM gt at the prompt R1 _ we type 2 7 4 ENTER 2 3 3 ENTER 3 3 3 R S gt at the prompt R2 _ we type 1 2 0 3 2 ENTER 1 1 2 9 6 ENTER 1 5 1 3 6 R S All set up we simply execute MSYS to obtain the solutions shought for ALPHA EACTORS LINKS ALPHA XEQ MSYS o Week 1 Week 2 Week 3 Cabbage Weight kg Broccoli Weight kg Note using OMR or OMC to output the elements of the matrix B you can see how the results are all integer values which speaks of the accuracy of the internal operaions taking advantage of the 13 digit math routines available in the OS for MCODE Note also that with these programs the integer results are shown without any zeros after the decimal point regardless of the current display settings FIX or otherwise OMR and OMC are extension functions pretty much like PMTM is and will be described in detail in chapter 3 c ngel Martin August 2013 Page 33 SandMatrix 4 Manual 2 3 3 Other Matrix Functions Utilities The remaining matrix functions also called utilities are those for copying and exchanging parts of matrices and miscellaneous extra arithmetic functions finding sums norms maxima and minima and matrix reduction Moving and Exchanging Matrix Sections _ Function Description sf put Exchange columns k and in a
61. 26 AVIEW 3 CF 00 27 PSE 4 V1 Vx VX menu options 28 VY 5 SF 27 User mode ON 29 ARCL Y 6 PROMPT 30 AVIEW Modulus Norm 31 PSE 8 SF 00 32 VZ 9 XEQ 05 33 ARCL Z 10 VMO SandMath s 34 AVIEW 11 V 35 PSE 12 GTO 00 36 GTO 02 start over DOT product 37 LBL 05 14 XEQ 03 38 AV1 prompt for V1 15 VA SandMath s 39 PROMPT 16 VF 40 FS 00 module 17 LBL 00 41 RTN yes go back 18 ARCL X 42 A V2 prompt for V2 19 PROMPT 43 CF 21 20 GTO 02 start over 44 AVIEW display first 21 LBLE CROSS product 45 ST lt gt A then exchange 22 XEQ 05 46 STOP 23 VXA SandMath s 47 END 24 VX You re encouraged to check the Vector Analysis ROM for a comprehensive implementation of a 3D Vector calculator as well as other geometry programs The Vectors ROM is completely self contained and only takes up one page 4k complementing the SandMatrix and the SandMath very effectively VCALC xy R Cos i j VeA E G lt gt ASN LBI VSTO XEQ a k e 59 T h VRCL__ KF k E TER CHS _ VCHS VADST c Angel Martin August 2013 Page 19 SandMatrix 4 Manual 2 2 1 Setting up a matrix Name Storage and Dimension The first group of matrix functions are used to create populate and store the matrices __ Function Description ft mputs _ _ _ 1 MATDIM Name in Alpha dimensions in X ra Returns name of current Matrix to Alpha 3 DIM Returns the dimension of Matrix Name in Alpha 4 M
62. 3 E3 4 5 INT 6 I lt gt J does E3 for integers 7 SIGN puts bbb eee in L 8 RDN 9 ENTERA 10 ENTERA LBL 06 12 CLX 13 RCL IND L 14 STO IND Y 15 ISG Y 16 CLX 17 ISG L 18 GTO 06 19 CLX 20 SIGN 21 22 I lt gt J 23 24 X lt gt Y 25 FRC 26 ISG X 27 INT 28 ES 29 30 31 END cnt l word in X 1 LBL PVAL RCL IND Z ISG Z GTO 14 10 X lt gt Y 11 SIGN 12 RDN 13 END 1 LBL DTC 2 LBL 05 RCL IND X ABS E 7 X lt Y GTO 06 X lt gt Z ISG X GTO 05 E ST Y cnt l word in X threshold value drecrease Y overwrite w zero cnt l word to X When using PCPY be careful that the register ranges for both polynomials do not overlap c ngel Martin August 2013 Page 71 SandMatrix 4 Manual 4 3 Polynomial Root Finders Once upon a time there was a program called POLYN available in HP s infamous MATH PAC That program was capable of calculating the roots of a polynomial up to degree five which perhaps back then when it first came out could be regarded as a remarkable affair but by today standards certainly isn t much to write home about nction Description Input Output 1 QUART Solution of Quartic Equation Polynomial coeffs in Memory PROOT Polynomial Roots Prompts for all data RTSN Subroutine mode of PROOT Polynomial coeffs in Memory 4 BRSTW Quadratic Factors Bairstow method Cnt l word in X reg The SandMatrix
63. 32 VIEW 00 show current index 6 J X prepare Alpha string 33 P 7 ASWAP swap string 34 CLST 8 MAT scalar multiplication 35 MMOVE copy result to 9 MNAME recall MNAME 36 DSE 00 decrement index 10 MEXP exponential 37 GTO 00 loop back if not ready 11 END done 38 ft 39 ARCL 01 MNAME 40 MAT copy result to 41 PURFL purge 42 p 43 PURFL purge P 44 MNAME recal MNAME to Alpha 45 END done Remarks Both MPWR and M 2 need one auxiliary matrix P to temporarily place the results of the matrix product Additionally MPWR needs a second auxiliary matrix as well An alternative listing for M 1 X that includes a convergency check is shown in next page Note how the calculations to check for the condition are a taxing step in that it requires a scratch matrix to calculate its norm On the positive side though it ll spare us the wait for a non convergent process that would take much longer until it s apparent so So after some consideration the longer version is now in the module c Angel Martin August 2013 Page 50 SandMatrix_4 Manual 1 LBL M1 NAME in Alpha 19 E 2 1fX 1 n 20 XY meets condition 3 STO 05 save it in ROS 21 GTO 00 yes go on 4 DIM dimansion 22 H no 5 lt not square 23 PURFL get nd of scratch 6 ADV MATRX show error 24 DIVRGNT T CCD MATRX show RUNNING PROMPT show error message 8 ASTO 01 save MNAME In ROI 26 LBL 9 27 CLA 10 a scratch matrix 28 ARCL 01
64. 35x 1 c Angel Martin August 2013 Page 66 SandMatrix 4 Manual 4 2 Managing Polynomials The remaing of this chapter is about polynomials Let s first cover those functions used to manage the data entry and output for them polynomial math and some handy utilities used in the other programs Function Description Input Output Deleting Tiny Coefficients Control word in X 8 P P Polynomial Sum Driver for PSUM PAP Polynomial Subtraction Driver for PSUM P p Product of Polynomials Driver for PPRD Division of Polynomials Driver for PDIV PCPY Polynomial Copy Control word in X reg destination in Y PDIV Euclidean Division Control words in Y and X regs PEDIT Edits Polynomial Coefficients Control word in X Reg PMTP Prompts for Coeffs in Alpha List Control word in X Reg X PPRD Polynomial Multiplication Control words in Y and X regs 17 PSUM____ Polynomial Addition amp Subtraction____ Control words in Y and X regs 18 PVAL Polynomial Evaluation Control word in Y argument in X 19 PVIEW Views Polynomial Coefficients Control word in X Reg 4 2 1 Defining and Storing Polynomials A polynomial is an expression of the form n n 1 2 Anat n 1F 49 ait io where a n 0 Or ma concisely Dar Polynomials can only be stored in main memory ie not as X mem files thus the way to handle them will be by a contro word of the form bbb eee which denotes the beginni
65. 4 3 R S P 5 4 R S II a we DD a A CFS Y N ida dl a 4 5 00000 R S a 3 40 00000 R S a 2 105 00000 R S a 1 100 00000 R S a 0 24 00000 Therefore the natural polynomial form is as follows G s 5 s 4 40 s 3 105 s 2 100 s 24 c ngel Martin August 2013 Page 86 SandMatrix_4 Manual Next the execution is transferred to RTSN which will calculate the roots following the iterative process explained in section 4 3 1 Remember that the accuracy is dictated by the number of decimals places set R S RUNNING R S Z 0 35557 R S Z 1 45609 R S Z 2 54395 R S Z 3 64442 POLZER is also rather long and dates back to the days the author attended EE School many moons ago so I m somehow attached to it 4 4 7 Partial Fraction Decomposition In algebra the partial fraction decomposition or partial fraction expansion of a rational fraction that is a fraction such that the numerator and the denominator are both polynomials is the operation that consists in expressing the fraction as a sum of a polynomial possibly zero and one or several fractions with a simpler denominator In symbols one can use partial fraction expansion where f and g are polynomials to change expression forms as shown below f x Y f x where gj x are polynomials that are factors of g x and are in general of lower degree Thus the partial fraction decomposition may be seen as
66. 4 3 MAT create scratch 18 ST X 25 ASWAP bring to hot spot 19 MTRACE tr 5 MDET determinant 20 RA get 25 to X reg 6 ABS asolute value 21 tr 25 T SORT 5 22 SORT t 8 MIDN 23 MAT A A s i 9 R get s to X reg 24 e y 10 ASWAP M4 25 MAT A A ft 11 ASTO T save MNAME in T 26 a 12 Mop 27 PURFL get rid of scratch 13 MAT R 5f 28 MNAME MNAME to Alpha 14 CLA 29 END done 15 ARCL T recall MNAME There it is directly without doing any iterations or finding inverses Your assignment now is to write a short program to calculate the square root of a 2x2 matrix applying the formula above Go ahead and try your hand at it or cheat and look below Note Not as trivial as you may think because the LU decomposition performing the determinant will conflict with other functions needed Therefore one scratch matrix should be used here as well Example calculate one square root of the matrix given below and compare its square power to it 5 a 1 8 245 2 v5 2 y5 2 2 5 1 245 2 5 This concludes the core matrix sections it s time now to embark into the fascinating journey of characteristic polynomials and eigenvalues as a prelude to the advanced polynomial chapter c Angel Martin August 2013 Page 56 SandMatrix_4 Manual 4 Polynomials and Linear Algebra Linear algebra is the branch of mathematics concerning vector spaces as well as linear mappings between such sp
67. 4 004 XEQ MATDI M 4 002 XEQ MATDI M The next step is entering the element values using CMEDIT because that is the only editor capable of editing complex matrices as we know CMEDIT RE 1 1 Complex matrix editor 10 200 RE 1 2 Loads the real and 0 200 RE 2 1 imaginary parts of ele 0 R75 200 R S RE 2 2 ments into RO the 0 170 R75 170 0000 coefficient matrix A R17 Dimensions the col 4 002 MATDIM 4 0020 umn matrix R17 to 4 x 2 for 2 complex rows and 1 complex column It needs 9 registers EMEDIT RE 1 1 Complex matrix editor 5 0 RE 2 1 Loads the real and O R S 0 R 0 0000 imaginary parts of ele ments into R17 the column matrix B Finally it comes the time for the real work using MSYS to solve the system and MCEDIT again in view only mode to review the results Keystrokes Display ALPHA R R 17 0 0000 Calculates the solution MEYS matrix X and loads it mto R17 SF 08 Sets editor for view only operation ALPHA R17 Displays the complex EMEDIT RE 1 1 0 0372 results for I and Is 1M 1 1 0 1311 which are in R17 If RE 2 1 0 0437 you have a printer at IM 2 1 0 1543 tached and set flag 08 before executing _CMEDIT all elements will be printed out automatically a he on c Angel Martin August 2013 Page 31 SandMatrix 4 Manual The solution is l 0 0372 0 1311 EE 0 0437 0 1543 As you can see this is an EE studen
68. 49 PNC XQ Disable PER enable RAM 120 ALIST 4544 024 gt 0952 ENCPOO 121 ALIST 4545 3B8 READ 14 d put F28 to F9 122 4546 2BC RCR 7 123 transfer staus of UF28 to F9 4547 248 SETF 9 124 adds the converted crh code 4548 1EE C C C ALL comma or period 125 to the LCD and prepares ALPHA 4549 013 JNC 02 overflows if COMMA cf28 126 454A 244 CLRF 9 comma CF 28 127 ALIST AAA 454B 3D9 PNC XQ Enable Display not cleared 128 ALIST 454C 01C gt 07F6 ENLCD 129 ALIST 454D 3B8 READ 14 d read right 130 ALIST 454E 3D8 C lt gt ST XP 131 ALIST 454F 148 SETF 6 132 ALIST 4550 24C FSET 9 comma or period 133 ALIST 4551 013 JNC 02 134 ALIST 4552 288 SETF 7 should replace the last chr 135 ALIST ee fe eee C lt gt ST XP with the same one w radix 136 ALIST 3es WRIT 15 e It LCD write 2222 137 ALIST LDI SEX 138 AUST BSE 02 ___ AAA A eatin OES 139 ALIST FSET 9 140 ALIST RN A O EEA reU a ante 141 ALIST C C 1 SEX 142 AUST 2 OR E A Elis SIIC A AAA 4 c Angel Martin August 2013 Page 92 SandMatrix_4 Manual go ahead and write a few more functions on your own A few suggestions 7 Program to calculate Eigenvectors from Eigenvalues General purpose p th root of a matrix General purpose Logarithm of a matrix Anything else you feel like going for This concludes the SandMatrix Manual Hope you have found it useful and interesting enough to keep re as a reference Better yet The End
69. C In performing this operat ion the calcula tor must be given the identit ies of the existing matrices A and B and also be told where to put the result matrix C However the result matrix can be the same as one of the input matrices All given matrices must al ready exist as named dimensioned matrices Naturally only A and B must contain valid data Some functions use only one input matrix and some functions automatically use one of the input matrices for output So the minimum number of matrices to specify is one and the maximum is three A matrix function checks the Alpha register for the names that is the locations of the matrices it needs for input and output Before executing that function you should specify all needed parameters on one line in the Alpha register separating each with a comma Alpha Register input matrix input matrix result matrix c ngel Martin August 2013 Page 22 SandMatrix_4 Manual Scalar Operations Scalar input and output must be in the X register and so this location does not need to be specified unless the function in question can use e ther a scalar or a matrix for the same input parameter To specify the X register use X For instance MATDI M requires a scalar input and a matrix name so you do not need to specify the X register On the other hand the scalar arithmentic functions such as MAT can use either two matrices or a scalar and a matrix for input Therefore you must s
70. Display Result XEQ PROOT ORDER Prompts for the degree 5 R S r aK X K Reminder of convention a5 prompts for coeffs showing current 2 R S a4 7 R S a3 20 R S a2 81 R S al 190 R S a0 150 R S STO Y N prompts for storage option y RUNNING At this point the different precision factors are shown which shoud be decreasing as the iterations converge towards the solutions and this repeated as many times at quadratic factors are needed c ngel Martin August 2013 Page 75 SandMatrix 4 Manual The solutions are shown below in FIX 5 Z 2 00000 J1 00000 and its conjugate not shown Z 1 00000 J3 00000 and its conjugate not shown Z 1 50000 And the matrix ROOTS is left in X Mem with 5 rows and two columns as follows 2 1 2 1 ROOTS 1 3 1 3 1 5 O To be sure it isn t the fastest method in town typically 5 6 iterations are needed each iteration takes a bout one full minute at normal speeds but it s applicable to any degree and stores the results in a matrix which makes it very useful as a general purpose approach Bairstow Method A faster program is BAIRS which also uses a factorization method but does not utilize any of the matrix functions Therefore the solutions are just prompted to the display but not saved into an X Mem file expects the coefficients already stored in main memory and
71. EDIT Matrix Editor Name in Alpha CMEDIT Complex Matrix Editor Name in Alpha You can create manipulate and store real and complex matrices The size and number of matrices is limited only by the amount of memory available in the calculator If you have extended memory you can also store matrices there To create a matrix you must provide its name and dimensions The function MATDI M uses the text in the Alpha register as its name and the dimensions mmm nnn in the X register to create a matrix It does not clear zero the elements of a new matrix in main memory but retains the existing contents of the previous matrix or registers Jt does clear the elements of a new matrix in extended memory You then enter values numeric or Alpha into a matrix via the matrix editors Naming a Matrix The name you give a matrix determines where it will be stored A matrix to be stored in main non extended memory must be named Rxxx where xxx is up to three digits You can drop leading zeros The matrix will be stored starting in Rxx For example ROO7 is the same as R7 which would store this matrix header in R07 As a shortcut if you specify matrix R its name and location will be RO A matrix to be stored in extended memory can be named with up to seven Alpha characters excepting just the letter X which is reserved to name the X register and the letter R followed by up to three digits which is reserved to name the main memory
72. LBL 00 LBL 02 16 MR recall element 34 DIM get dimansion 17 multiply 35 END end 18 MSR store and increase column c Angel Martin August 2013 Page 54 SandMatrix_4 Manual Sum of Diagonal and Crossed Elements products ONL Other two functions directly related to the eigenvalues are and xIJJI They compute sums of pairs of element multiplication either for those in the diagonal aii a kk or for crossed i e opposite ones aij aji with i j excluding the diagonal 2 1 4 2 3 0 Armed with these functions the characteristic polynomial of a 3 x 3 matrix can be expressed very succinctly as we ll see in Chapter 4 of the manual Example Calculate the trace and the sums of diagonal and crossed elements for the matrix below 2 2 Tr A 2 1 1 2 1 1 3 MDPS 2 1 1 1 2 1 1 2 0 1 Yaij aji 2 1 4 24 3 0 10 Program listings easy does it element wise BE MINAME in Alpha iros MNAME in Alpha 2 DIM get dimension 2 DIM get dimansion 3 l J not square 3 l J not square 4 ADV MATRX error message 4 AVD MATRX show error 5 INT n 5 CF 00 default case 6 E 6 3 7 n 1 7 X lt Y isi gt 3 8 E3 E 1 00 n 1 8 SF 00 flag case 9 CLA 9 0 initial sum 10 STO M 10 MSIJA set pointer to 1 1 11 LBL 00 11 LBL 06 12 RCL M k 00 n 1 recall element 13 E end of row 14 E3 E 1 001 yes juom out 15 k 1 00n no increase row 16 STO N recall element 17 LBL 01 multiply 18 RCL
73. LBL 10 2 CF 01 33 N 1 order P1 3 GTO 00 34 PROMPT n1 O 4 Beppe 35 4 36 37 E3 E 1 00 n 4 combined data entry 38 3 product 39 4 00 n 4 yes go there 40 STO 00 division 41 PEDIT 42 XEQ 05 adjust index reminder cntl word 43 ENTER push stack store 44 N 2 order P2 45 PROMPT n2 show quotient 46 n2 eee1 47 I lt gt J 0 00 n2 eee 1 a 48 eee1 1 00 eee 1 n2 multiplication 49 PEDIT 50 RCL 00 bbb eee1 51 X lt gt Y bbb eee2 52 LBL 05 53 ENTER bbb eee2 54 I lt gt J eee bbb2 55 INT eee2 56 E 57 eee2 1 combined data entry 58 END show result reminder done c ngel Martin August 2013 Page 70 SandMatrix_4 Manual 4 2 3 Deleting tiny Coefficients Evaluating and Copying Polynomials PVAL j PCPY These three small routines were written by JM Baillard to perform the following housekeeping chores e Evaluate a polynomial value entered in the X reg e Copy a polynomial from a source to a destination location and e Delete small coefficients below 1E 7 wich typically appear due to rounding errors in the intermediate operations This has a cumulative effect that can alter the final result if not corrected The evaluation leaves the result value in X The other two functions return the destination control word to X upon completion Below you can see the program listings for these always a beauty to behold JM s mastery of the RPN stack 1 LBL PCPY 2 RCL Y bbb eee1
74. M k 00 n 1 add to partial sum 19 INT k end of matrix 20 RCL N k 1 00n no do next row 21 INT k 1 21 LBL 00 22 I lt gt J does E3 for integers 22 FC 00 order gt 3 23 k 1 00 n k 1 23 RDN yes get result to X reg 24 MSIJ sel pointer 24 FC C 00 order gt 3 25 MR recall element 25 RTN yes done 26 XoY 26 0 27 I lt gt J does E3 for integers 27 MSI set pointer to 1 1 28 MSIJ set pointer 28 RDN ann to X reg 29 RDN 29 MR aoo 30 MR recall element 30 a00 ann 31 e multiply them 31 add to the sum 32 ST O add to partial sum 32 END done 33 ISG N increase row 34 GTO 01 next element in row 35 ISG M increase colum 36 GTO 00 next colum 37 RCL O partial sum to X reg 38 MNAME recall mname to Alpha 39 END done c ngel Martin August 2013 Page 55 SandMatrix 4 Manual Appendix Square root of a 2x2 Matrix A square root of a 2x2 matrix M is another 2x2 matrix R such that M R 2 where R 2 stands for the matrix product of R with itself In many cases such a matrix R can be obtained by an explicit formula Let A B M p where A B C and D may be real or complex numbers Furthermore let T A D be the trace of M and 0 AD BC be its determinant Let s be such that s 2 0 and t be such that t 2 T 2s That is t EVT 25 Then if t 0 a square root of M is 1 A s B R 7 C pis s v8 1 LBL SQRT2 MAAME in Alpha 16 pan prepare string 2 J A Prepare Alpha string 17 ARCL T MA M
75. MNAME to Alpha 11 MATDIM 29 MILN matrix logarithm 12 MIDN make it identity 30 RCL 05 L n 13 CLA 31 TER prepare string 14 ARCL 01 MNAME to Alpha 32 ASWAP 15 1 AE prepare string 33 mMAT element multiplication 16 MAT intermediate result 34 MNAME MNAME to Alpha 17 ASWAF 35 MEXP exponential matrix 18 FRA get its norm 36 END done The scratch matrix is removed in case there is divergence or reused to calculate the logarithm if not thus at least it s not all a waste of time If there is no convergence you may still go ahead and hit R S after the error message to see how the precision factor keeps increasing until the OUT OF RANGE condition A general purpose algorithm for the p th root The principal p th root of a non singular matrix A det A 0 may be computed by the algorithm MO A Mk 1 Mk 2 1 p 2 Mk I p 1 Mk 1 p XO I Xk l Xk 2 p 2 Mk 1 1 p 1 Mk where I is the Identity matrix Mk tends to I as k tends to infinity Xk tends to A 1 p as k tends to infinity The convergence is also quadratic if A has no negative real eigenvalue c Angel Martin August 2013 Page 51 SandMatrix 4 Manual Lie Product of two Matrices MLIE gt The lie product is defines as the resultimg matrix obtained from the difference between the right and left multiplications of the matrices or in equation form Lie A B Lie B A AB BA Example Calculate the Lie product for matrices 1 2 4 1 4
76. Poles to Zeros and back 86 Partial Fractions Expansion 87 Appendix M and END 90 c ngel Martin August 2013 Page 4 SandMatrix_4 Manual SandMatrix_4 Module Revision K Matrix Extensions for the HP 41 System 1 Introduction The release of the CCD Module by W amp W in 1983 provided convenient and reliable tools for matrix algebra in the 41 platform for the first time It was an MCODE quantum leap ahead beyond the very many user programs written on the subject in the previous years Looking back it s clear that the ARRAY FNS was beyond a doubt an amazing landmark in the legacy of the 41 platform So much so that rather than re invent the wheel HP decided to use it almost in its entirety in the Advantage Pac only enhancing it with the major matrix operations sorely missing in the CCD implementation which incidentally were the subject of the majority of Matrix programs written for the CCD Perhaps because the relative tardiness of its appearance with the HP 42S already on the horizon or due to other factors like the HP 48S luring folks into RPL the fact is that Matrix programs using the Advantage Pac functions were very few and far in between The demise of PPC and the newsletter wars that followed suit certainly didn t encourage the scene either and the end result was slightly disappointing in terns of net results About 30 years later the SandMatrix picks up the gauntlet and compiles a collection of notewor
77. RES in Alpha matrix product in RES W amp W GmbH MAT element multiplication value in X OP1 X in Alpha aij aij x W amp W GmbH MAT addition of scalar value in X OP1 X in Alpha aij aij x W amp W GmbH MAT element substraction value in X OP1 X in Alpha aij aij x W amp W GmbH MAT Division by scalar value in X OP1 X in Alpha aij aij x W amp W GmbH MATDIM Dimensions a matrix mmm nnn in X OP1 in Alpha Matrix Dimensioned W amp W GmbH MAX Maximum element OP1 in Alpha Element value in X W amp W GmbH MAXAB Absolute maximum OP1 in Alpha Element value in X W amp W GmbH MDET Determinant OP1 in Alpha Determinant in X HP Co MIN Minimum element OP1 in Alpha minimum element in X W amp W GmbH MINV Inverse Matrix OP1 in Alpha Matrix replaced w Inverse HP Co MMOVE Moves part of a matrix Lj k l b m n in XYZ Elements moved W amp W GmbH MNAME Get current Mname to Alpha none Matrix Name in Alpha W amp W GmbH MR Recall element from pt none value in X HP Co MRC Recall and advance in Column OP1 in Alpha element in X increased i W amp W GmbH MRC Recall and back one in Column OP1 in Alpha element in X decreased i W amp W GmbH MRIJ Recall ij pointer of current none pointer in X W amp W GmbH MRIJA Recall ij pointer of Alpha OP1 in Alpha pointer in X W amp W GmbH MRR Recall and advance in Row OP1 in Alpha element in X increased j W amp W GmbH MRR Recall and back one in Row OP1 in Alpha element in X decreased j W amp W Gm
78. S A I DT BSE SHIFT B A I DT BSE Re transposes A to the original A C DT DET 12 7800 Det A B 1 1 b117 Enters the editor for B and displays old elements 16 5 R S 2 1 b12 Enters the new value for bi 22 1 CHS R S A I DT BSE Enters b and returns main menu E SE A I DT BSE Solves the system AX B placing X in B SHIFT D 1 1 11 2887 displays the solution matrix R S 2 1 8 2496 R S or J A I DT BSE Exits the editor c Angel Martin August 2013 Page 13 SandMatrix 4 Manual Example 2 Find the inverse of the complex matrix i 1 3 3i i 64 71 rh 1 d Ln Note that the original MATRX has been slightly edited in the SandMatrix so that the program sets the required SIZE if not enough registers are currently available to store the matrices so you don t need to worry about that mundane detail This example is also interesting because also shows how to make corrections to the data entered by mistake Keystrokes Display Comments XEQ MATRX RL CX Starts the MTRX program B CX ORDER Selects a complex Matrix 2 R S A I DT BSE Dimensions a 2x2 complex matrix A R S RE1 1 x11 Enters the editor and sisplays old value 1 R S IM1 1 y11 ditto for the imaginary part 2 R S RE1 2 x12 3 R S IM1 2 y12 4 R S RE 2 1 x21 Wrong entry Should be 3 not 4 1 002 A RE1 2 3 000 Mo
79. SandMatrix 4 Manual e wou a F a a 5 A MS ea m e aba Bip E M MM LIA T 2x2 ee Ee al il Ml E y lt p B a y he j T E m 5 a E ar a E e ee S aar E Bi in E gt e z ahon d s Bisa pom a at r a e sg 3 5 i sil Tai sili t a a a e os z os A A 6 Se o eo a t A D SE Bs Goss El j cl DA eee ce umm SE Ful Se Se ee Se ae aee a a oe Niro E MA ae l ed O 2 Cara ra 6960 aha DU LA ii A A ee TLE E ss MA a en a Ep 9 25 Aaa a y o ma z ET ma r Y m ies i i pm a i Em liia E ea E pe Baam a a Se oe al eee AAA ds e a Fu o Sa oo m Ast a p aoan m e E ue e i o a gt ae a l ee l A SSK AR AR Dr i lad gt _ E AS SS ae ae Seen 6 beg gt E i ae kb a 5 Ta A l E 0 0 0 0 5 _ ch lt A Pr ES me me oe pe ee a er A 1 rtemsians ra l i a E oS ES E m z 1 a E User s Manual and Quick Reference Guide Te EN e a R PO eo S M ytri Page 1 August 2013 7 Written and programmed by Angel M Martin 7 c Angel Martin August 2013 SandMatrix 4 Manual This compilation revision 3 4 5 Copyright 2012 2013 ngel M Martin Acknowledgments Documentation
80. When you enter new elements into A you destroy its old elements c Angel Martin August 2013 Page 11 SandMatrix 4 Manual Instructions MATRX has two menus to show you which key corresponds to which function The initial menu you see is to select a real ox complex matrix picture on the left below initial Menu Main Menu NEW A TRANS POSE We UDJII 50000 DO00D0D080 OOUE D 0 After you make this selection input the order of the matrix and press R S you will see the main menu picture on the right above This menu shows you the choice of matrix operations you have in MATRX Press J to recall this menu to the display at any time This will not disturb the program in any way To clear the menu at any time press Back Arrow This shows you the contents of the X register but does not end the program You can perform calculations and then recall the menu by pressing However you don t need to clear the program s display before performing calculations e The program starts by asking you for a new matrix It has you specify real vs complex and the order dimension of a square matrix for A e The program does not clear previous matrix data so previous data possible meaningless data will fill your new matrices A and B until you enter new values for their elements e Each element of a complex matrix has two values a real part and an imaginary part and requires four times as much memory to sto
81. aces Such an investigation is initially motivated by a system of linear equations in several unknowns Such equations are naturally represented using the formalism of matrices and vectors __ Function Description Input Output 1 CHRPOL Characteristic Polynomial Under prgm control 122 EIGEN Eigen Values by SOLVE Under prgm control 3 EV_ Subroutine for EIGEN Under prgm control 4 63 _ Eigen values 3x3 Matrix in X Mem 5 EV3X3 Eigen values 3x3 Prompts Matrix Elements 6 JACOBI Symmetrical Eigenvalues Under prgm control 4 1 Eigenvectors and Eigenvaules An eigenvector of a square matrix A is a non zero vector v that when the matrix is multiplied by v yields a constant multiple of v the multiplier being commonly denoted by A That is Av Av The number A lis called the eigenvalue of A corresponding to v In analytic geometry for example a three element vector may Ay pmm A be seen as an arrow in three dimensional space starting at the ii origin In that case an eigenvector of a 3x3 matrix v is an arrow whose direction is either preserved or exactly reversed Y after multiplication by A Y AENA iH The corresponding eigenvalue determines how the length of the arrow is changed by the operation and whether its direction is reversed or not determined by whether the eigenvalue is negative or positive O X JX A vector with three elements may represent a point in three dimensional space relative to some
82. after having found its determinant you would have needed to invert the matrix twice to change the LU decomposed form back to the original matrix LU Decomposition The ower upper LU decomposition is an unrecognizably altered form of a matrix often containing Alpha data This transformation properly occurs in the process of finding the e Solution to a system of equations MSYS SE in the MATRX program e Determinant MDET DT in MATRX program e Inverse MI NV I in MATRX program The first two of these operations convert the input matrix to its LU decomposed form and leave it there whereas inversion leaves the matrix in its inverted form When you use functions that produce an LU decomposed form there are several things that you need to be aware of e You cannot edit an LU decomposed matrix unless you edit every element Also care must be exercised when viewing an LU decomposed matrix Certain operations can alter elements without your knowledge refer to Editing and Viewing an LU Decomposed Matrix below for more details e You cannot perform any operation that will modify the matrix other than MINV because the LU status of the matrix will be cleared and it will become unrecognizable Operations that have this effect are R lt gt R C lt gt C MS MSR MSR MSC MSC MMOVE intramatrix MSWAP and TRNPS e LU decomposition destroys the original form of the matrix So if you perform MSYS or MDET and then try to look at
83. age regis ters one register being used as a status header A complex matrix uses 2m x 2n 1 registers where m is the number of rows in the complex matrix and n is the number of columns in the complex matrix A matrix in extended memory has a file length of m x n 2m x 2n for a complex matrix Its file type is unique to matrices Do not use the function CLFL with a matrix in extended memory this destroys part of the file s header information Instead use PURFL to purge the entire matrix Changing Matrix Dimensions If you redimension a matrix to a different size then the existing elements are reassigned to new elements according to the new dimensions Extra old elements are lost extra new elements take on the values already present in the new registers except in extended memory where new elements are set to zero Redimensioning 2 x 3 to2 x2 aa PJ Tp Eh PA md last 45 6 3 4 3 6 Redimensioning 2 x 3 to2 x4 i 2 3 Il 2 3 4 ml 45 6 5 Tt 7 This is what happens each time you dimension a new matrix since the old elements from the previous current matrix remain until you change them Caution When MATDIM is used to redimension a matrix stored in extended memory the position of the matrix pointer is not readjusted If the pointer happened to be positioned to an element that is outside the new bunds of the redimensioned matrix it must be repositioned to be within the new bounds by executing either MSIJ or MSIJA with valid
84. amplel Solve xf 2 x 35 x 36 x 180 0 2 ENTER 35 ENTERA 36 ENTER 180 XEQ QUART gt gt gt gt X1 6 000 X2 3 000 X3 2 000 X4 5 000 c Angel Martin August 2013 Page 72 SandMatrix_4 Manual Example2 Solve xt 5 x 11 x 189 x 522 0 5 ENTER 11 ENTER 189 ENTER 522 XEQ QUART gt gt gt gt Z 2 J5 000 note how true integer values don t display zeros after the decimal point X3 3 000 X4 3 000 Example3 Solve xf 8 x 26 x 168 x 1305 0 8 ENTER 26 ENTER 168 ENTER 1305 XEQ QUART gt gt gt gt Z 2 J5 000 note how true integer values don t display zeros after the decimal point Z 6 J3 000 c Angel Martin August 2013 Page 73 SandMatrix 4 Manual 4 3 2 General case degree N RTSN Given a polynomial F P z Y ajz a 1 an 0 i 0 This method is based on quadratic factorizations that is one quotient polynomial of degree 2 plus a reminder polynomial of degree one reducing the original degree by 2 and thereby changing the expression as follows P z P z Q z R Z with P z bi z4n i i 2 1 n 2 This will then be repeated until the reduced polynomial P x reaches degree one or two Let Q x x42 px q and R x rx s Then the reduced polynomial coefficients are given by and we have the following expressions for the coefficients of the reminder r b n 1 s b n 2
85. aqq cos z 2 apq sinz cos z bpq 0 and the remaining elements are symmetric where sin z w sqrt 2 1 sqrt 1 w 2 and cos z sqrt 1 sin Z with L apq M app aqq 2 and w L sign M sqrt M L This is iterated using a strategy for selecting each non diagonal element in turn until all non diagonal elements are zero when rounded to a specific number of decimal places When this is so the diagonal contains the eigenvalues Program remarks The accuracy and running times are display settings dependent however the computed eigenvalues are very often more accurate that it d appear for instance usinf FIX 5 it s quite possible to have eigenvalues accurate to 8 decimal digits The program is written to be as fast as possible and to occupy the minumim amount of program memory the matrix is stored taking into account its symmetry so that all elements are stored only once as aji aij For a nxn matrix minimum size is Ya n 2 n 7 25 41 10 6 Example Find the eigenvalues for the 4x4 matrix A 41 68 17 10 10 17 5 3 6 10 3 2 c Angel Martin August 2013 Page 65 SandMatrix 4 Manual Keystrokes Display Result XEQ J ACOBI ORDER Prompts for dimension 4 R S al 1 Data entry starts 25 R S al 2 41 CHS R S al 3 10 R S al 4 6 CHS R S a2 2 Note how the symmetric 68 R S a2 3 2 elements are skipped 17 CHS R S a2 4 10
86. as the benefit of saving one entry in the FAT which would be needed for the subroutine label Line 4 uses the header function SNDMTRX 4 which in program mode adds the text ORDER to the display not ALPHA This saves bytes and keeps the contents of ALPHA unchanged 2 2 4 3D Vectors Mini Calculator Lastly 3DV is a mini vector calculator use it to calculate the Module of a vector or the DOT and CROSS products of two 3D vectors It s basically a small menu driven shell that uses functions VMOD V A and VXA available in the auxiliary FAT within the SandMath One of the operand vectors is placed in ALPHA registers M N O therefore their names Its prompt looks like this Which assumes no assignments are done on the A C and E keys and that USER mode is on Data entry is also under program contol and nice alphanumeric mnemonics describe the result s The module and the dot product are left in X upon completion For the cross product case the three components are sequentially displayed with a pause in between them They re also placed in the stack registers Z Y X for subroutine use c Angel Martin August 2013 Page 18 SandMatrix_4 Manual The program listing is below note how this trivial little application manages to make good use of some of the sub functions in the SandMath module as well as the interesting way to use the ALPHA register for the vector components 25 ARCLX new start
87. ates the trace to the determinant of the exponential of a matrix as follows Jacobi s formula det e etl MTRACE uses a single element approach basically adding all the elements in the principal diagonal For small to mid size matrices this is faster than a block approach redimensioning and transposing the matrix such as the one sketched below coutesy of Thomas Klemm DIM n n 1 zt DIM 1 n DET IF l I oo i I gt Io gt OF gt 1 gt gt lu El 00 0 I Of 11 l Ol Here s the sweet and short SandMatrix program listing compared side to side to a block approach alternative implementation which also requires a scratch matrix if one wishes to keep the original matrix unchanged as well as some additional steps for Alpha housekeeping c ngel Martin August 2013 Page 53 SandMatrix 4 Manual Note how the alternative approach function SUM is used whch removes the need to calculate the determinant in the last step of the sketch Regardless it s bigger and takes longer excution time even without the test for square matrix condition 1 LBL MTRACE MNAME in Alpha 1 LBL TRACE2 2 DIN 2 I prepare Alpha string 3 IHI square 3 MAT make scratch 4 ADW MATRX no show error 4 AS WAP place In hot spot 5 0 Initial sum value 5 DIN gets ts dimensions 6 MSIA sets pointer to 1 1 6 E T LBL 05 7 je gt 0 001 a MRR recall element B
88. atrix Editor from the Advantage seen in the previous chapter There are as follows Function Description Input Output PMTM Prompt Matrix by Rows Matrix name in Alpha IMR Input Matrix by Rows _____ MatrixmameinAlpha_____ OMR_____ Output Matrix by Rows Matrix name in Alpha _____ OXR Output Rowk Matrix name in Alpha kkk in X reg Of all these more remarkable one is of course PMTM which expedites element data entry to the maximum possible in the 41 platform almost as if it were a full fledge editor in a graphical screen 5 The idea is to use the Alpha register as repository for all the elements separating the individual values by spaces entered using the ENTER key The data input is terminated by presing R S The back arrow key is always active to correct a wrong entry and will terminate the function if Alpha is completely cleared PMTM allows for negative and decimal numbers to be entered thus the CHS and RADIX keys are also active during the data entry prompt Furthermore the logic will only allow one occurrence of these per each element within the prompt string PMTM knows how many rows should be input it is part of the matrx dimension thus the prompts will continue to appear until the last row is completed A row counter is added to the promt to indicate the current row being edited If you enter fewer elements in the prompt than existing columns the remaing elements will be left unchanged and the execu
89. bH MS Store element at pointer value in X OP1 in Alpha Element stored HP Co MSC Store and advance in Column value in X OP1 in Alpha element stored increased i W amp W GmbH MSIJ Sets pointer of current matrix iii jjj in X pointer set W amp W GmbH MSIJA Sets points of Matrix in Alpha iii jjj in X OP1 in Alpha pointer set W amp W GmbH MSR Store and advance in Row value in X OP1 in Alpha element stored increased j W amp W GmbH MSWAP Swapps part of a matrix lj k l b m n in XYZ Elements Swapped W amp W GmbH MSYS Linear Systems OP1 OP2 RES in Alpha Resolves Linear System HP Co PIV Sets pointer to pivot element Col in X OP1 in Alpha Element value in X W amp W GmbH c ngel Martin August 2013 Page 7 O COON DU bh 0 N PR R lt gt R R gt R RMAXAB RNRM RSUM SUM SUMAB TRNPS YC C MEDIT CMEDIT MPT ADV MATRIX AMROW I lt gt J l J IMIC IMR LU M21 X MA2 MAT MATP MCON MDPS MEXP MFIND MIDN MLIE MLN MPWR MRDIM MSQRT MSORT MSZE MTRACE MZERO OMC OMR OCX ORX PMTM R aRR 213 ADV POLYN BRSTW CHRPOL DTC EIGEN EV3 EV3X3 JACOBI OPFIT P P p_p P P Row Exchange k lt gt l Row comparison test Absolute maximum Row Norm Row Sum Element Sum Absolute Values Sum Transpose Adds Y Col I to Col k Matrix Editor Complex Matrix Editor Matrix Prompt Section Header Input Row Swaps indexes Isi je Input Matrix by Columns Input Matrix by Rows Tests for L U Decomposed
90. bels as explained in the owner s manual for the HP 41 assigned to keys A E J a b and d These local assgnments are overriden by any User key assigments you might have made to these same keys thereby defeating this program Therefore be sure to clear any existing User key assignments of these kep before using this program and avoid redefining these keys in the future Example 1 Given the system of equations at the beginning of this section find the inverse determinant and transpose of A and then find the solution matrix of the equation AX B 18 72 x 16 5 13 0 9 x 22 1 Keystrokes Display Comments XEQ MTRX RL CX Starts the MTRX program A RL ORDER Selects a real Matrix 2 R S A I DT BSE Dimensions a 2x2 square matrix A 1 1 a11 Enters the Editor and displays old value 3 8 R S 1 2 a12 enters the new value for aj 7 2 R S 2 1 a21 1 3 R S 2 2 a22 9 CHS R S A I DT BSE enters a and returns main menu B I A I DT BSE Inverts A SHIFT A 1 1 0 0704 Displays the current contents R S 1 2 0 5634 of A after the inversion R S 2 1 0 1017 R S 2 2 0 2973 R S A I DT B SE B 1 A I DT BSE Re inverts A to the original B A I DT BSE Transposes A A 1 1 3 8000 Displays the current contents R S 1 2 1 3000 of A after the transposition R S 2 1 7 2000 R S 2 2 0 9000 R
91. ce of broccoli is 0 86 kg Determine the weights of cabbage and broccoli he sold each week Week 1 Week 2 Week 3 Combined Weight kg Combined Value 130 32 112 96 151 36 The following set of linear equations describes the two unknowns the weights of cabbage and broccoli for all three weeks where the first row of the constant matrix represents the weights of cabbage for the three weeks and the second row represents the weights of broccoli Since the constant matrix is not a column matrix you must use MSYS and not the SE function in the MATRX program c ngel Martin August 2013 Page 32 SandMatrix_4 Manual da i Where the subindices indicate the crop 1 broccoli 2 cabbage and the week 1 2 3 and the first row describes the weight equations and the second the prices relationship Calling FACTORS the coefficients matrix and LINKS the costant matrix we first create them by dimensioning in X Memory as follows ALPHA FACTORS ALPHA ALPHA LINKS ALPHA 2 002 XEQ MATDI M 2 003 XEQ MATDI M Next we ll use PMTM to input all the element values Note that even the longest row has 20 characters including the separator blanks which is below the limits of the ALPHA register length of 24 characters max With FACTORS in Alpha we type XEQ PMTM gt at the prompt Ri _ we type 1 ENTER 1 R S gt at the prompt R2 _ we type 0
92. d matrix To use MATRX you do not need to know how the calculator stores and treats matrices in its memory The next chapter lists and defines every matrix function in the pac including those called by MATRX Using these functions on their own requires a more intimate knowledge of how and where the calculator stores matrices What this program can do Consider the equations 3 8 Xi 7 2 X2 16 5 1 3 Xi 7 0 9 X2 22 1 for which you must determine the values of x1 and x2 These equations can be expressed in matrix form as AX B where A is the coefficient matrix for the system B is the column or constant matrix and X is the solution or result matrix 3 0 Xy 16 5 A X and B 1 3 U9 Xy 22 1 For such a matrix system the MATRX program creates dimensions a square real ar complex matrix A and a column matrix B You can then Enter change edit or just view elements in A and B Invert A Transpose A if A is real Find the determinant of A if A is real Solve the system of simultaneous equations by finding the solution to AX B The size of your matrix is limited only by available memory each real matrix requires one register plus one register for each element If you want to store more than one matrix you will need to use the matrix function MATDI M described in the next chapter The MATRX program does not store or recall matrices it works with a single square matrix A and a single column matrix B
93. e relatively short program but here too the data requirements are equally hefty as three auxiliary matrices are required for a total of 4 x dim A registres needed either in main or X memory including the original matrix 3 Ea ETE 2 DIM get dimension 31 SF 00 yes flag this fact 3 l J is it square 32 X YR are they equal gt 4 ADV MATRX no show error 33 GTO 02 yes jump over 5 CF 00 34 CLA no keep at it 6 FNRM initial norm 35 ARCL 01 7 STO 00 store it in ROO 36 prepare Alpha string 8 ASTO 01 matrix name to R01 37 MINV invert matrix 9 RDN dimension to X reg 38 MAT copy in auxiliary 10 l 39 MINV undo the inversion 11 MATDIM auxiliary matrix P 40 Q 4 Q 12 gt 41 MINV invert auxiliary 13 MATDIM auxiliary matrix Q 42 MAT sum it to partial result 14 MIDN 43 QX 15 LBLOO 44 2 16 2 45 MAT divide by scalar 2 17 MINV 18 MAT auxiliary matrix 47 Po 19 CLA 48 ARCL 01 20 ARCL 01 49 MAT 21 HP 50 FC 00 were norms equal 22 MAT 51 GTO 00 no next iteration 23 px 52 PURFL purge P 24 53 q 25 MAT 54 PURFL purge Q 26 FNRM Frobenius norm 55 27 VIEW X show progress 56 PURFL purge 28 X lt gt 00 swao with old norm 57 MNAME matrix name to Alpha 29 RCL 00 recall new one again 58 END done As usual this routine will result in ALPHA DATA if the matrix is in LU decomposed form c Angel Martin August 2013 Page 48 c Ang g g SandMatrix_4 Manual Matrix Integer Powers and Roots i T
94. ed impose some restrictions to the matrices These are generally not checked by the programs thus in some instances there won t converge to a solution Suffice it to say that the programs are not fool proof and assume the user has a general understanding of the subjects so they won t be used foolishly Matrix Exponential In mathematics the matrix exponential is a matrix function on square matrices analogous to the ordinary exponential function Let X be an nxn real or complex matrix The exponential of X denoted by e X or exp X is the nxn matrix given by the power series X ox E where X 0 is the identity matrix I The above series always converges so the exponential of X is well defined Note that if X is a 1x1 matrix the matrix exponential of X is a 1x1 matrix consisting of the ordinary exponential of the single element of X Finding reliable and accurate methods to compute the matrix exponential is difficult and this is still a topic of considerable current research in mathematics and numerical analysis The SandMath uses a direct approach so no claims of discovering new algorithms exp A 1 4A A 2 A 3 ASK c ngel Martin August 2013 Page 44 SandMatrix_4 Manual The program adds new terms until their contribution is negligible i e it results in the same matrix after addng it This by itself poses an interesting question how to check whether two matrices are the same Obviously
95. ed yi values Then once all the data have been input and both matrices are allocated and populated lines 46 47 solve the system for the coefficients of the polynomial using MSYS e Finally lines 48 59 establish a loop that labels and outputs all the coefficients Example Rumor has it that the seemingly trigonometric function y cos 5 arccos x is actually a 5th degree polynomial in disguise Attempt to retrieve its true form If it is indeed a 5th degree polynomial we can retrieve its true form by fitting a 5th degree polynomial to a set of 6 arbitrary data points x y Any set with different x values 1 0 lt x lt 1 0 will do but for simplicity s sake we ll use x 0 0 2 0 4 0 6 0 8 and 1 Proceed like this set Rad mode 4 decimals XEQ RAD FIX 4 start the program XEQ POLFIT N specify degree 5 5 R S X1 enter ist x value 0 R S X2 enter 2nd x value 0 2 R S X3 enter 3rd x value 0 4 R S X4 enter 4th x value 0 6 R S X5 2 enter 5th x value 0 8 R S X6 enter 6th x value 1 R S Y1 enter 1st y value 0 ACOS 5 COS R S Y2 enter 2nd y value 0 2 ACOS 5 COS R S Y3 enter 3rd y value 0 4 ACOS 5 COS R S Y4 enter 4th y value 0 6 ACOS 5 COS R S Y5 enter 5th y value 0 8 ACOS 5 COS R S Y6 enter 6th y value 1 ACOS 5 COS R S al 1 0250E 9
96. ements jjj pointer by one Storing and Recalling the Element s Value alone or sequentially The following functions provide a faster more automated alternative to adjusting the pointer value to access each element These combine storing or recalling values and then incrementing or decrementing the i or j index so that the pointer is automatically set to the next element _ Function Descriptiom_ z Imputs 9 MS Stores value in X reg into current element Value in X Reg 10 MR Recalls current element to X reg None Returns element to X reg advances pointer to next element in column advances pointer to next element in row advances pointer to next element in column Returns element value to X reg advances pointer to next element in row Returns element value to X reg decrements pointer to previous in column Returns element value to X reg o Sitch ear fon Rar decrements pointer to previous one in row Returns element value to X reg c Angel Martin August 2013 Page 24 SandMatrix_4 Manual When the end of a column or row is reached the pointer s index advances to the next or previous column or row If the pointer s index is moved beyond the boundaries of the matrix it cannot be moved back using these functions You must use MSIJ or MSIJA The following sequence of keystrokes will create the matrix ABC in extended memory 5 6 7 ABC 9 10 Keystrokes Displa Comments ALPHA ABC 2 003 XEQ
97. ensional Dot product 3D Vectors none Text in Alpha x in X A B in Alpha Text in Alpha cntl words in Y X Eq in ROO Mname in Alpha Driver for Major Matrix Ops Mname in Alpha Cnt l word in X V1 in Stack V2 in Alpha prompts for coeffs Promppts V V VX Displays Order Last char deleted INT x appended to Alpha B A in Alpha Removed from left to comma cntl word result in X Writes equation in Alpha Yes No Do it true Under prgm control Calculates P A V2 in Stack V1 in Alpha result in Matrix performs operation A ngel Martin W amp W GmbH Angel Martin Angel Martin W amp W GmbH JM Baillard Angel Martin Angel Martin HP Co Angel Martin Angel Martin Angel Martin Angel Martin CCD MTRX Section Header none Displays Running Angel Martin Column exchange k lt gt l kkk Ill in X Columns swapped W amp W GmbH Column Maximum Col in X OP1 in Alpha Element value in X W amp W GmbH Column Norm Col in X OP1 in Alpha colum norm in X W amp W GmbH Column Sum OP1 RES in Alpha Sum of Cols in RES matrix W amp W GmbH Matrix Dimension OP1 in Alpha dimension placed in X W amp W GmbH Frobenius Norm OP1 in Alpha value in X W amp W GmbH Increase row index OP1 in Alpha increased i HP Co Decrease row index OP1 in Alpha decreased i HP Co Increase column index OP1 in Alpha increased j HP Co Decrease column index OP1 in Alpha decreased HP Co M M Matrix Product OP1 OP2
98. ext xi all rows done MX complete Make it current get its dimensions N 1 00 N 1 get N 1 avoid using a register specify vector MY to be created in X MEM creates and dimensions vector MY in X MEM ask for yi data and store them in MY specifies 1st element of the vector and resets the index to the 1st element loop for next data and store them in MY recalls the current value of the index forms the prompt to ask for yi appends the index to the prompt appends to the prompt prompts the user to enter yi stores it in MY and updates the index are we done with all elements not yet go back to ask for the next yi all yi stored Specify MX MY for the system solves the system for the coefficients retrieve and display each coeff specifies 1st element of the coeffs vector resets the index to the 1st coefficient loop to retrieve the next coefficient recalls the current value of the index forms the prompt to display each coeff appends the index to the prompt appends to the prompt retrieves the value of the current coeff appends the value to the prompt shows the value to the user are we done outputting all the coeffs not yet go back for the next coefficient all done End of execution As the Advantage ROM can work with matrices directly in X Mem POLFIT doesn t use any main RAM registers and so it will run even at SIZE 000 This has the added advantage pun intended of avoiding any register conflict
99. f A lt 1 Moreover the direction will be precisely the same if A gt 0 and flipped if A lt 0 If A 0 then the length of the arrow becomes zero 4 4 4 Eigenvalues and eigenvectors of matrices Characteristic Polynomial The eigenvalue equation for a matrix A is Av Av which is equivalent to A Al v 0 where I is the n x n identity matrix It is a fundamental result of linear algebra that an equation M v O has a non zero solution vif and only if the determinant det M of the matrix M is zero It follows that the eigenvalues of A are precisely the real numbers A that satisfy the equation det A AT 0 The left hand side of this equation can be seen to be a polynomial function of the variable The degree of this polynomial is n the order of the matrix Its coefficients depend on the entries of A except that its term of degree n is always 1 A This polynomial is called the characteristic polynomial of A and the above equation is called the characteristic equation or less often the secular equation of A c Angel Martin August 2013 Page 58 SandMatrix_4 Manual SOLVE based Implementation El GEN There are three Programs in the SandMatrix that calculate eigenvalues The first one is aptly named and is a brute force approach using the direct definition of the eigenvalue given above What makes it interesting is the direct application of SOLVE of FROOT in the SandMath pl
100. f xi yi data pairs The xi are all different and they need not be equidistant You need to know the y value at the location x which is not one of the xi You start the program XEQ POLI NT and enter x at the prompt x R S Then you enter the first data pair x0 R S preferably one which has an x_i close to x y0 R S The program returns yO You enter another data pair R S The program returns the results of a linear x1 R S interpolation y1 R S You enter another data pair R S The program returns the results of a x2 R S quadratic interpolation y2 R S You enter another data pair R S The program returns the results of a cubic x3 R S interpolation y3 R S and so on until you exceed the SIZE of your calculator Going beyond the cubic interpolation is seldomly useful High order interpolations become increasingly sensitive to round off errors and inaccuracies of the input data The number of data registers used depends on the order of the interpolation An nth order interpolation which uses n 1 pairs of data occupies the registers ROO to R 2n 4 e g a cubic interpolation needs all registers up to R10 If a printer is connected the interpolation results are printed out and the empty R S entries are not required Example Given the table below with a set of vapor pressure data for superheated water what is the vapor pressure at 200 C 473 15 K Here s the sequence followed to resolve it
101. functions to manipulate individual matrix elements A specific element is identified by the value 777 for its location in the i th row of the j th column You can drop leading zeros in the i index and trailing zeros in the j index The value of the pointer defines the current element Setting and recalling the Pointer 11 MSIJA Sets element pointer of matrix in Alpha Name in Alpha iii jjj in X reg 2 MSIJ Sets element pointer of current matrix iii jj in X reg 13 MRIJA Recalls element pointer of Matrix in Alpha Name in Alpha iii jjj in X reg 4 MRIJ Recalls element pointer of current matrix iii jjj in X reg The following functions increment and decrement the element pointer rowwise iii or column wise jjj If the end of a column is reached with the i index or the end of a row is reached with the j index then the index advances to the next larger or smaller column or row and sets flag 09 If the index advances beyond the size of the matrix both flags 09 and 10 are set These functions always either set or clear flags 09 and 10 If the conditions listed above don t occur the flags are cleared every time the functions are executed Incrementing and Decrementing the Pointer The following functions were not in the original CCD ARRAY FNS group therefore are HP s __ Function Description puts Increments iii pointer by one Decrements iii pointer by one none Increments jjj pointer by one 8 J Decr
102. had its solution matrix found because MDET and MSYS transform the input matrix A into its LU decomposed form Refer to LU Decomposition for more information However you can retrieve the original form of A from its decomposed form by inverting it twice execute MINV twice The LU decomposition does not interfere with the ca Iculations for MINV MSYS or MDET Example 1 63 9 Find the determinant of the inverse of the transpose of the matrix 1 4 3 Storing it in Main Memory starting in Register RO a 8 First make sure that the calculator SIZE is set at least to 10 to accommodate the elements plus the header register typing XEQ SI ZE 010 Next we begin by creating the matrix in main memory using the name RO in Alpha and the dimension in X ALPHA RO 3 003 XEQ MATDI M Since the elements are all integer numbers this is an ideal candidate for PMTM XEQ PMTM gt at the prompt R1 _ we type 6 ENTER 3 ENTER CHS 2 R S gt at the prompt R2 _ we type 1 ENTER 4 ENTER CHS 3 R S gt at the prompt R3 _ we type 2 ENTER 3 ENTER CHS 1 R S And now the festival begins type XEQ TRNPS RO is transposed XEQ MINV RO which was transposed is inverted XEQ MDET gt 0 040 is the solution c Angel Martin August 2013 Page 27 SandMatrix 4 Manual Note that if you had wantecacad to find the transpose of the original matrix
103. hem in a result vector Vector in Alpha Ep TT the sums in a result vector Vector in Alpha For CSUM and RSUM the number of elements in the result matrix vector must equal the number of columns rows in the input matrix Miscellaneous Arithmetic functions Matrix Reductions Description Inp Input Output Outp ut oS eee ees matrix by value in Y ref and adds it to y in Y reg corresponding element in column It changes the elements in colum is the maximum absolute value of an element on or below the diagonal 19 R gt R Compares elements in rows k and I If Matrix name in Alpha kkk IIl in X reg and only if the first non equal Outputs YES if first non equal element in k is greater than its element in row k is greater than corresponding element in then the element in row I NO in all other case comparison is positive for the do if true rule of programming c Angel Martin August 2013 Page 35 SandMatrix 4 Manual The last two functions are not operating on a matrix but are auxiliary for the FOCAL programs Description _ Inp Input Output Output Function Descrip the absolute value of the Value in X integer part of the number in X to the contents of the Alpha register 21 Appends a matrix prompt rrr ccc rrr ccc in X reg the contents of the Alpha ena dropping leading zeros in each part Note that AIP and AI NT in the SandMath are very simi
104. hether this is the value you want If you want to change the element you see just enter the new value and press R S You do this for a brand new matrix as well as for correcting or altering a single value If you press R S without entering a new value the current value remains unchanged Viewing without editing If you set flag 08 the editor will let you only view the elements not change them The display appears without the at the end of the line 1 1 1 0000 If you have a printer attached while flag 08 is set it will print out all the elements of the matrix without pausing Directly accessing any element You can directly access any specific element while the editor is active and the User keyboard is also active To access the element in the i th row and the j th column enter iii jjj and press A This is as in the MATRX program You can drop leading zeros in iii and trailing zeros in jjj For a complex matrix you can directly access the real pari of element i j Then use R S to access its imaginary part You can drop leading zeros in the i part and trailing zeros in the j part A zero part defaults to a 1 Exiting the Editor To leave the editor before it has reached the last element do either e Press J e Try to access a nonexistent element For instance in a 4 x 4 matrix press 5 A How to Specify a Matrix Given the matrix multiplication operation AB C you know A and B and are looking for the product matrix
105. his application will be dealt with using a relatively brute force approach in that the powers will be computed by successive application of the matrix multiplication therefore the restriction to integer powers calculates the general case n whilst is used to square a matrix i e n 2 The first requires the matrix name in Alpha and the exponent in the X register whereas for the second only the matrix name in Alpha is needed The exponent may also be a negative integer For that case the inverse matrix is calculated first and the positive integer power is used for it Lastly for n 0 the result is the identity matrix of course A feeble attempt is also made for the integer roots calculation the function M 1 XJ will attempt to calculate the x th root of a matrix using the general expression A exp 1 x Ln A which is only valid when abs llA II lt 1 Despite the inherent limitations of these programs they are interesting examples of extension of the native matrix function set and therefore their inclusion in the SandMatrix Examplel Calculate the 7 th power of the matrix below Type XEQ MPWR and the result is 7851276 8652584 31076204 A 8911228 9823060 35267932 5829472 6422156 23076808 Example 2 Calculate the 5 root of matrix A below then compare its 5 power to the original matrix 1 2 0 1 0 3 A 01 0 8 0 1 0 1 0 2 0 9 The results are as follows 1 034632528 0
106. including W amp W for the array functions set renamed here as CCD MATRIX Many of the routines in this manual include the program listing this provides an opportunity to see how the functions are used and of course adds completion to the documentation The function groups are distributed in both lower and upper pages as follows e The lower page contains the general intro section plus the CCD Matrix set Very much like the lower page of Advantage Pac minus the digital functions e The upper page has the Advanced Matrix and Polynomial sections Basically all new and additional to the Advantage Pac e The second bank in the upper page is practically identical to that in the Advantage with a few changes made after removing the Digital functions as well It mostly contains the MCODE for the CCD Matrix functions and the major matrix calculations MSYS MINV MDET TRNPS The SandMath checks for the presence of its two dependencies ie The Library 4 and the SandMath Note that if the SandMath module is not plugged in the calculator the following warning message is shown every time the calculator is switched on but not halting the polling points process SAN IGMA TH hi Fr MJ USER c ngel Martin August 2013 SandMatrix 4 Manual 2 Lower Page Functions in detail The first section groups the auxiliary functions used for ALPHA string management plus some leftover functions that either didn t belong to the other
107. lar but AI NT won t take the absolute value This fact is useful to append integer vaules to alpha without decimal numbers but respecting the sign Note that MPT in the SandMatrix is an enhanced version written in MCODE that replaces the mini FOCAL program used in the Advantage Example Calculate the Row Column and Frobenius norms for the matriw 3 0D A 2 6 lAlle D 2 OO a J TTE max 210 1 lt j lt n Ti which is simply the maximum absolute column sum of the matrix max gt a jl y which is simply the maximum absolute row sum of the matrix 1sism The results are Row Norm 19 Column Norm 15 Frobenius Norm 14 38749457 The Frobenius norm will come very handy for some programs in Chapter 3 as convergence criteria and to determine whether two matrices are equivalent in reduction algorithms Ai xB A x By A 3 X By c ngel Martin August 2013 Page 36 SandMatrix_4 Manual 3 Upper Page Functions in detail This chapter is all above and beyond the matrix functionality present in the Advantage Pac a true extension of its capabilities into new and often uncharted territories 3 1 The Enhanced Matrix Editor s Often the most tedious part of a matrix calculation becomes the data entry for the input matrices and the review of the results With this in mind the SandMatrix includes convenient alternatives to MEDIT the standard M
108. last Alpha char 86 ALIST gt 44B9 ABSP4 recall deleted char value store in A for comparisons 130 LDI S amp X check for SPACE space lt space gt 87 ALIST 38 ALIST 89 ALIST 90 ALIST 91 ALIST PNC XQ complete the logic 92 ALIST gt 452B CHUNK4 93 ALIST G repeat the prompt 94 ALIST gt 44E0 KC1O 710I 95 ALIST PAHC SEX carry if different y 96 ALIST 452C 01F JC 03 97 ALIST 452D 348 SETF 12 allow new space entry 98 ALIST 452E_ OA3 3JNC 20d___ gt eee BALLET 2 FFE y 99 ALIST Po 452F 130 LDI SEX check for chr 100 ALIST 4530 02D mm _ char value 101 4531 366 PAHC SEX carry if not 102 Executed within DELCHR 4532 102F JC 05 103 an opportunistic routine 4533 1 34C PFSET 12 is there SPACE chr 104 just grouping common code 4534 017 JC 02 105 4535 0c4 CLRF 10 i allow new entry 106 ALIST 4536 063 JNC 12d gt BAILOUT 107 ALIST Po 4537 198 C M ALL recall deleted char value 108 ALIST 3D8 C lt gt ST XP Got a radix If so we neet to 109 ALIST 14C FSET 6 replace it without comma 110 ALIST 043 JNC 08 111 ALIST Enable Display not cleared 112 ALIST ENLCD 113 ALIST 144 CLRF 6 remove the radix value 114 ALIST 284 CLRF 7 both if need be 115 ALIST 3D8 C lt gt ST XP recall deleted char value 116 ALIST 3E8 WRIT 15 e write itin display 117 ALIST 184 CLRF 11 Re allow comma writing 118 ALIST Po 4542 3E0 RTN 119 ALIST 43 1
109. lements without modifying them e Set flag 08 before executing MEDIT or CMEDIT This allows you to view the elements without modifying them c Angel Martin August 2013 Page 28 SandMatrix_4 Manual Header Register X ray The graphic below shows the different fields in the Matrix header register 14 bytes in total 13 12 11 10 9 8 7 a 4 a7 2 1 O 2 File Addr of Columns Active if File Size Note that a matrix file in X mem has its type set to 4 in leftmost byte and that the matrix dimensions can be derived from the information in the file size field nybbles 0 1 2 and the number of columns field nybbles 6 7 8 whereby Number of rows File size Number of Columns Lastly the pointer field stores the information on the current element as a counter starting from the first element 1 to the last nxm Given the length of this field it follows that a maximum of 4 096 elements FFF can be tracked equivalent to a square matrix of dimensions 64 x 64 or any equivalent m x n combination You can use the function to check whether a matrix is in its LU decomposed form It ll return YES NO in Run mode and in a program will skip the next line when false i e it s NOT decomposed Working with Complex Matrices When working with complex matrices it is most important to remember that in the calculator a complex matrix is simply a real matrix with four times as many elements Only the MATRX
110. lving a system of linear equations __ Function Description sid put MDET Finds the Determinant of a square matrix Matrix Name in Alpha MINV Inverts and replaces the square matrix Matrix Name in Alpha 4 MSYS Solves a system of linera equations Matrix Name A Name B in Alpha 4 MTRPS Transposes and replaces the real matrix Matrix name in Alpha This is where the Advantage really took the original CCD implementation to its full fulfillment as the CCD was sorely lacking the major operations no doubt due to the size constrains in a module that already had tons of other wonders and was packed bursting to its seams I recall the awe with which we used to run MINV and the other functions just a single keystroke doing the same as all those intricate FOCAL programs did using Gaussian algorithms element pivoting and row simplification simply amazing back then It was the ultimate Matrix function set pretty much surpassing the HP 15C implementation in this area If you re reading this now I suspect you probably had a similar experience too but enough reminiscing and let s get on with the manual The output of these operations always replaces the original matrix with the result Moreover for MDET and MSYS the result matrix is placed in its LU decomposed form which makes it not suitable for some direct subsequent operations Nole You cannot transpose or change any element of a matrix A that has had its determinant found or has
111. ncluding the file headers The last point to remember about MPOL is that it uses data registers ROO and RO1 which therefore cannot be used to store the polynomial coefficients e ROO has the polynomial control word and is used as counter for the loop execution e RO1 has the matrix name It s left unchanged Below you can see the program listing for MPOL not a long program albeit not as short as a simple polynomial evaluation for real variables Note the use of function 1 J to check for square matrix as well as the shortcut ADV MTRX that puts the error message WOT SQUARE in the display and terminates the execution 01 LBL MPOL r 33 Lape 02 DIM 24 ARCLO1 d 03 l J is it square o 25 PAH 04 ADVMITRX no prompt error 26 MFM d 05 RDN cnt l word to X ae P o6 E 3 28 CST r o7 029 MMOVE 08 STOOO 30 ISGO00 next index o9 ASTO 01 31 GTO0O loop back 10 DIM 32 XEQ02 pr 33 PURFL purge auxiliary mat 42 MATDIM 34 MNAME bring result name 43 g 35 RTN 4 MATDIM 36 LBLO2 15 TE 37 MH r 416 ARCL 01 38 MIDN 17 pe X A P 39 X E 18 RCL IND 00 40 RCLINDOO next coeff f 419 MAT initial value 4 MAT 20 ISG 00 next index A42 PpP r 43 MAT add it to partial result 22 XEQ 02 4 END The auxiliary matrix is needed because unfortunately M M does not allow the result product matrix to be the same as any of the multi
112. nd polynomial and the result are typically input in the X Y and Z registers of the stack As follows Addition Subtraction Euclidean Division Multiplication ist Reg of result in X bbb eee of reminder in Y bbb eee of result in X bbb eee of quotient in X bbb eee or result in X Because registers ROO to RO3 are used internally they cannot be used to hold the polynomial coefficients ie all control words must start at bbb 4 at least Note also that none of the register ranges should overlap In addition for the Euclidean Division the original polynomials are overwritten with the results quotient and reminder Let a x ao x a1 x an 1 X an and b x bo x b1 x Dm1 X Dm then there are only 2 other polynomials q x and r x such that a b q r with deg r lt deg b Note that PDIV does not work if deg a lt deg b but in this case q 0 and r a Example 1 Find the result of the polynomial product of a x b x where a x 2 x 5 x 21 x 23 x 3 x 5 and b x 2 x 3 x 1 We ll use for convenience It ll automatically store the coefficients of the operand polynomial in registers R04 to R09 and in registers R10 to R12 respectively The result polynomial will be stored starting with register R20 leaving the operand polynomials untouched The solution is p x 4 x 4 x 55 x 114 x 84 x 24 x7 12 x 5 Example 2 Find the quotient and reminder for the polynomial divi
113. ndMatrix 4 Manual 4 4 3 Prime Factors Decomposition p This section describes the three functions provided in the SandMatrix related to Prime factorization Function Description Input Output 11 PRMF Prime Factors Matrix Form Argument in X reg From Factors to Number Prime factors in Matrix file TOTNT Euler s Totient function Argument in X reg The first one extends the basic prime factorization capability in the SandMath PFCT The difference is that whereas PFCT only uses the Alpha register to output the result as Alpha string here the prime factors and their multiplicities are also stored in a matrix in X Mem named PRFM This ensures that no information will be lost scrolled off the display if the length exceeds 24 char and also provides a permanent storage of the results You can use to check the result it re builds the original argument from the values in the PRMF matrix using the obvious relationship X I PF i m i for i 1 2 primes Euler s Totient function In number theory Euler s totient or phi function p n is an arithmetic function that counts the totatives of n that is the positive integers less than or equal to n that are relatively prime to n The graphic below shows well sort of the first thousand values of p n mr O 200 400 600 800 1000 Examples Calculate the prime factors and the totient for the following numbers n PF phi 1 477 7 211 1 260 819 735
114. ng and end registers that hold the polynomial coefficients a i The coefficients are stored starting with the A ghest order term first ie xn in register bbb and ending with the zero th term last stored in register eee It follows that the degree of a polynomial n verifies n eee bbb For instance the control word 1 007 represents a polynomial of degree 6 which coefficients are stored as follows a 6 in RO1 a 5 in R02 a 4 in R03 a 3 in R04 a 2 in RO5 a 1 in RO6 and a 0 in RO7 The Polynomial Editor There are three functions available in the SandMatrix to enter and review polynomials in the calculator The main one is PEDIT which takes the input from the control word in the X register and sequentially prompts for each coefficient value The first thing it does is present a reminder of the convention used relating the subindex to the power of the variable for each term A nice feature is that it ll check for available data registers to complete all the storage re adjusting the calculator SIZE if necessary PEDIT does not use any data registers itself c Angel Martin August 2013 Page 67 SandMatrix 4 Manual Note that includes in the prompts the current value held in the corresponding data register so you don t need to type a new one if it s already correct Alternatively you can use to review the coefficients without any editing capabilities In this mode the prompts don t have the question mark
115. nsions of the matrices are the same If this is not the case the i j notation does not apply Matrix multiplication on the other hand calculates each new element by summing the products of the first matrix s row elements by the second s column elements The number of columns in the first matrix must equal the number of rows in the second matrix The result matrix must have the same number of rows as the first matrix and the same number of columns as the second matrix If there is a scalar operand it must be in the X register and X must be specified in the Alpha register The input specifies matrix name A or X matrix name B or X result matrix C in Alpha register The outputs are respectively Cy Ay x Or Ep A AU Ey Xx By or Cy x by or ee Cy ay by for all i j in C Cy 2 Oy for all j in E Cy ay Xx OF Cy ag Xx OF Cy x by or Ej X By oF cy aj X by for all i j in C Cy ay by for alli fin J The true matrix multiplication calculates each new element i j by multiplying the i th row in A by the j th column in B The input is the three matrix names in Alpha where C must be different from the two operands A and B The output is Oy gt a X Dn where A has p columns and B has p rows c Angel Martin August 2013 Page 26 SandMatrix_4 Manual 2 3 2 Major Matrix Operations The major matrix operations are inversion finding the determinant transposition and so
116. ons These are MSYS Solving simultaneous equatiohs MINV Matrix inverse MAT Matrix add MAT Matrix subtract MAT Matrix scalar multiply but only by a real scalar in X reg M M Matrix multiplication Both the input and result matrices must be complex Example 2 Engineering student A C Dimmer wants to analyze the electrical circuir shown below The impedances of the components are indicated in complex form Determine the complex representation of the currents il and i2 fa 10 fr The system can be represented by the complex matrix equation AX B or 10 200i 2006 J 5 2001 200 30 f 0 We ll use the individual matrix functions instead of MATRX program already covered in the previous sections c Angel Martin August 2013 Page 30 SandMatrix_4 Manual The main thing to sort out in this example is the dimension of the matrices involved The coefficients matrix A is a 2 x 2 complex matrix thus as per the previous paragraphs we will need 4x4 1 17 registers The independent terms matrix B is a 2 x 1 complex matrix thus will need 4x2 1 9 registers This makes for a total of 26 registers needed for the example therefore we adjust the SIZE accordingly first typing XEQ SIZE 026 Next we create the two matrices in main memory starting at ROO and R17 respectively Note the shortcut in the RO name dropped the zero ALPHA R ALPHA ALPHA R17 ALPHA
117. ough they do not require it This means you can use MSYS on a matrix system from MATRX You can convert an existing 2m x 2 complex column matrix to the 2m X 1 form by transposing it redimensioning it to 1 x 2m then retransposing it There is no easy way back Accessing Complex Elements If you use the complex matrix editor CMEDIT or the editor in the MATRX program you can access complex elements as if they were actual complex numbers Otherwise such as when you use pointer setting functions you must access complex elements as real elements stored according to the 2m x 2n scheme given above Storage Space in Memory Since the dimensions required for a complex matrix are four times greater than the actual number of complex elements an m X n complex matrix being dimensioned as 2m x 2n realize that the number of registers a complex matrix occupies in memory is correspondingly four times greater than a real matrix with the same number of elements In other words think of a complex matrix s storage size in terms of its MATDIM or DIM dimensions not its number of complex elements Using Functions with Complex Matrices Most matrix functions do not operate meaningfully on complex matrices since they don t recognize the different parts of a complex number as a single number the results returned are not what you would expect for complex entries Valid Complex Operations Certain matrix functions work equally well with real and complex functi
118. pecify X if you want to use it The Current Matrix The current matrix is the last one accessed used by a matrix operation If the Alpha register is clear and you execute a matrix function that requires a matrix specification the current matrix is used by default If there is no current matrix UNDEF ARRAY results The result matrix of a matrix function becomes the current matrix following that operation To find out the name of the current matrix execute MNAME Its name is returned into the Alpha register overwriting its previous contents Default Matrix Parameters If you don t specify any or all the matrices that a matrix function needs then certain default parameters exist Default parameters are those automatically assumed if you don t specify them The most common default you will probably use is the current matrix If you don t specify a particular matrix name and the Alpha register is clear then the default matrix is the current one For matrix operations requiring up to three matrix names in the Alpha register the following table gives the conventions to interpret the parameters Alpha Register s Contents Matrices Specified X reg A B current current current c Angel Martin August 2013 Page 23 SandMatrix 4 Manual 2 2 2 Storing and Recalling individual Matrix elements The matrix editor provides a method of storing and reviewing matrix elements For programming you can use the following
119. perform any calculations thus it s just an embellishing addition to CURVE The original listing was originally published in the AECROM manual and it s reproduced here practically unaltered HieLBL EG B2 XE IHI A At AYIER Ra RTH a5 GTO EG Acel BL Be A athiX As ETH 49461 Bl 6 iziatbhst ii ETH 201 BL Be 13 atipi id RTH ISeLBL 63 16 Ke daxtbae SeLEL a4 19 aztb 28 RTH 2JeLBL 85 22 abtk 234 ETE LEAL Bb 25 abhi iD 26 ETH er LBL 8 20 aetibii 29 RTH 3BPLEL BS 31 atbLHx 32 RTH J3HLEL 9 id abba 33 RTH G5FLEL 1A af atthe cCA At2 a8 RTH F9eLEL 11 de atbxtckt 4 EIH 420LBL 12 43 akebe dd RTH 454LBL 13 46 getC X bit2irce 47 br d2 FTH 494LBL 14 JA aetiiib LHX t2Y of F4g J2 RTH JJ LBL 15 a4 iria Ethic c ngel Martin August 2013 Page 77 SandMatrix 4 Manual 4 4 2 Polynomial interpolation POLINT gt The program POLINT follows the Aitken s interpolation method Its an elegant simple implementation and a nice example of utilization of the capabilities of the platform It was written by Ulrich K Deiters and it is posted at http www hp41 org LibView cfm Command View amp ltemID 600 The program performs polynomial interpolations of variable order on xi yi data sets with the order determined by the number of data pairs It is applied as follows You have a set o
120. picks up where the SandMath left things off providing functions to calculate the roots of the quadratic and cubic equations ie polynomials of degrees 2 and 3 The next step would then be a Quartic equation or polynomial of degree 4 4 3 1 Quartic Equation solutions QUART QUART solves the equation x a x b x c xtd 0 If you have a polynomial not in monic form which leading coefficient is not 1 simply divide all the equation by this coefficient With this convention we can use the stack registers T Z Y X to hold the coefficients a b c and d which provides a convenient method for data input The method used can be summarized as follows First the term in x is removed by a change of argument leading to 4 2 x p x q x r 0 E Then the resolvant z p z 2 p 41 z 16 q 64 0 is solved by CROOT and if we call z z2 and z the 3 roots of this equation the zeros of E are x z sign q 22 z3 x aa sign q 4 a E a 9 Note that QUART uses ROO to R04 for scratch therefore those registers cannot hold the polynomial The data output is done automatically by the program presenting the roots as either real or complex conjugated This is done using the status of flags 01 and 02 as appropriate but the user needs not to concern him or herself with the decoding rules The output uses function ZOUT from the SandMath which uses J to denote the imaginary unit i Ex
121. plication factors At least we double use it for other intermediate calculations as well identity matrix products killing two birds with the same stone MPOL is representative of the kind of routine that makes the extensions to the base matrix functions set of the Advantage hopefully it has whet your appetite and are looking forward to seeing more and that we will in later sections of the manual c ngel Martin August 2013 Page 16 SandMatrix_4 Manual 2 2 3 N dimensional Vector Operations DOTN is an all MCODE implementation of a n dimensional vector dot scalar product the norms of each operand and the angle between them Originally written by JM Baillard the input parameters are the control words for each vector in registers X and Y more about this later and the result value are placed in the stack Obviously the vector components must be input in the appropriate registers which you can do using any of the available input programs available in the SandMatrix will be seen with detail in the polynomial section later in the manual Incidentally the code for DOTN is located in the second bank of the upper page taking advantage of the available room after the removal of the digital functions Example Calculate the scalar product of vectors U 2 3 7 1 and V 3 1 4 6 storing their components in registers R01 R04 for U and R06 R09 for V For the data input we have several choices here we ll Use the
122. r A with aij ij Solution pA x 75 349 x3 66 x2 60 x 0 x1 66 890 x2 0 897 x3 2 24000E 9 Example 2 Calculate the eigenvaules for A with aij 1 2 3 9 Solution pA x 0 076 x3 15 x2 18 x 0 x1 16 117 x2 1 117 x3 2 89100E 9 It is therefore a relatively easy exercise to write a program to deal with this case as shown in the program listing in next page c Angel Martin August 2013 Page 61 SandMatrix 4 Manual 1 LBL EV3X3 2 CF 06 clear subroutine flag 3 EV 4 E 5 E3 E 1 001 6 3 7 3 003 8 MATDIM 9 IMR enter elements GTO 06 a set subroutine flag 14 CCD MATRX show RUNNING 15 MTRACE calculates tr A 16 CHS change sign 17 STO 02 save it in RO2 18 MDPS get the sum of minors 19 STO 01 as a combination 20 2 IJJI of functions into RO1 21 ST 01 22 MDET calculate determinant 23 CHS change sign 24 STO 00 25 FS 06 subroutine mode 26 GTO 11 yes skip prompting 27 CF 21 28 CFS Y N offer choice 29 AVIEW 30 Bror JdecodetheY N input 31 GETKEY 32 41 33 X Y 34 GTO 11 choice rejected 35 30 Program remarks 36 37 38 39 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 68 69 XHY GTO 01 wrong key 3 choice accepted coefficientes loop b AIP jaja ARCL IND X PROMPT E X lt 0 last one GTO 11 yes jump over GTO 05 no get next one LBL 11 proceed with roots E fill stack
123. re as an element in a real matrix The promprs for real parts x11 x12 etc are 1 1 1 2 etc The prompts for complex parts x11 i y11 x2 i y22 etc are RE 1 1 IM 1 1 2 etc Remarks Alteration of the Original Matrix The input matrix A is altered by the operations finding the inverse the determinant the transpose and the solution of the matrix equation You can re invert A and re transpose A to restore the orignal form of A However if you have calculated the determinant or the solution matrix then A is in its LU decomposed form To restore A simply nvert it twice The LU decompostion does not interfere with any subsequent MATRX operation except transposition and editing do not attempt to edit an LU decomposed matrix unless you intend to change every element For more information on LU decomposition refer to LU Decomposition in the next chapter Matrix Functions c Angel Martin August 2013 Page 12 SandMatrix_4 Manual Matrix Storage The MATRX program stores a matrix A starting in RO of main memory it is named RO Its column matrix B is stored after it and the result matrix X overwrites B Refer to the chapter Matrix Punctions for an explaniation of how matrices are named and stored and how much room they need MATRX cannot access any other matrices with the exception of the previous RO and its corresponding column matrix Redefined Keys This program uses local Alpha la
124. riate digit in the matrix header register O CON DIM bh 0N PR Pie iP iP iP iP ob Din alu NN R O LU LU LU LU LU LU LU LU LU LU LU LU LU LU LU LU Header Header Header LU PORT DEP Jumps to Bank_2 XQ adds 4 to XS gt A5D9 LNCHO lt parameter gt JNC 01 ENROM1 C N ALL PT 9 C 0 PT 0B9 PNC GO False O5A gt 162E SKP restore bank 1 header register LU digit 065 NC GO True O5A gt 1619 NOSKP Lastly and just in case you though that functions PMTM and PMTP are actually not a big deal which would be the logical conclusion if you only look at their FOCAL program listing here is in all its gory detail the listing for its MCODE heart function MROW I ll spare you the more onerous details but suffice it to say that it was an involved assignment And don t forget that another function is also used to support the matrix prompt mode ANUMDL although in this case I just had to copy HP s code from the HP IL Development Module thanks HP WO CON DMR WY FR NIN ININ IN N R Pl RP le Pl PIP rererere U BIWIN FP OO 0 J O UO alu NRO AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW AMROW Header Header Header Input Matrix Row Header Header ngel Martin AMROW B65D 0C4 CLRF 10 start anew no CHS yet 184 CLRF11 B65F 344
125. riginal argument Angel Martin PMTP Prompts for Polynomial cntl word in X prompts for complete list Angel Martin POLFIT Polynomial Fit Under prgm control calculates polynomial fit Valentin Albillo POLINT Aitken Interpolation Under prgm control interpolation made Ulrich Deiters POLZER From Poles to Zeros Under prgm control shows coeffs and roots Angel Martin PPRD Polynomial Product cntl words in Z Y bbb in X cntl word result in X JM Baillard PRMF Prime Factors Decomposition number in X prime factors in XMEM Matrix ngel Martin PROOT Polynomial Roots Under prgm control Shows all roots ngel Martin PSUM Polynomial Sum cntl words in Z Y bbb in X cntl word result in X JM Baillard PVAL Polynomial Evaluation Cntl word in Y x in X Result in X JM Baillard PVIEW Polinomial View Cntl word in X Sequential listing of coeffs ngel Martin QUART Quartic Equation Roots coeefs in Stack a4 1 shows results JM Baillard RTSN Roots subroutine Under prgm control calculates roots ngel Martin TOTNT Euler s Totient Function argument in X Result in X ngel Martin HEV Subroutine for EIGEN Under prgm control Under prgm control Angel Martin Sand Matrix_4 Manual Functions in blue are all in MCODE Functions in black are MCODE entries to FOCAL programs Light blue background denotes new or improved in this revision I have adapted most of the FOCAL programs for optimal fit in the SandMatrix but as you can see the original authors are always credited
126. river for MROW that also takes advantage of the auxiliary functions in the SandMatrix 1 LBL PMTM 2 0 MSIJA position pointer to 1 1 recall pointer row number prompts for string default reset one reached yes exit store element end of row no do next element end of matrix no do next row 19 MNAME recall Mname 20 END done MROW is the first function listed in CAT 2 within the ADV MATRIX group and rightfully so Note that even if PMTM is not strictly an MCODE function de facto it is a hybrid one and therefore it s denoted in blue color all throughout this manual If PMTM is the beauty then MROW is the beast If you re interested you can review the MCODE listings for it in appendix M Below are two examples of the lists being edited for the first two rows of a given matrix d and L The built in logic allows for just one negative sign and one radix character per each value entry Note that MROW is also used by PMTP the Polynomial Input function which has a very parallel structure to PMTM and is used to enter the coefficients of a polynomial into data registers It will be covered in the polynomial section later on The remaining routines in this section all deal with Input and Output of the matrix elements depending on whether it s done following the Row or Column sequence as well as two functions to only view one specific row or column OXR and OXC c ngel
127. s the contents of ALPHA located to the right of a comma i e after the comma but not including it It is adapted from CLA in the CCD Module EQT is an extension to the Curve Fitting functions in the SandMath Use it to display and write in Alpha one of the 16 the equations available for CURVE It requires the equation number 1 to 16 in ROO Easy does it ST lt gt A simply exchanges the contents of the stack and the four Alpha registers M N O P Used in 3D vector operations where one of the operands is stored in Alpha c Angel Martin August 2013 Page 10 SandMatrix_4 Manual 2 2 Other functions in the Header section Easy Matrix Program Driver for Major Matrix Ops 2 SQR Tests for Square Matrix Mname in Alpha 3 6 3DV 3D Vectors Prompts V _V VX MATRX is the main driver program provided in the Advantage Pac for the major matrix calculations MDET MINV SIMEQ TRNPS Nice and easy maybe the only one to use for users not needing any further functionality MTR was part of the same program but has been eliminated in this revision The following extract describing the use of MATRX is taken from the Advantage Pac manual and it s included here for convenience and completeness It s useful to revise the underlying concepts as well 2 2 1 The Matrix Program This chapter describes the matrix program MATRX the easy user friendly way to use the most common matrix operations on a newly create
128. s with other programs POLFIT creates two matrices in X Mem namely MX and MY which aren t destroyed upon termination Retaining MX allows the user to compute the coefficients of another polynomial using the same x data but different y data In that case the x data need not be entered again only the new y data must be entered Further as the MX matrix is left in LU decomposed form after the first fit the second fit willproceed much faster Retaining MY allows the user to employ the polynomial for interpolating purposes root finding numeric integration or differentiation etc Lines 2 11 prompt the user for the degree of the polynomial then allocate the system matrix in Extended Memory MATDI M and reset the indexes MSI c Angel Martin August 2013 Page 83 SandMatrix_4 Manual e Lines 12 22 set up a loop that will fill up the rows of MX Notice the use of the miscellaneous function AIP to build the prompt and MSR to store the value and automatically advance the indexes to point to the next element e Lines 23 27 form a tight loop that computes each power of xi and uses MSR to store it and advance the indexes Flag 9 logs if we re done with the column in which case we would proceed to the next row If so Flag 10 is then checked to see if we re done with all the rows e Once the system matrix has been populated lines 30 45 do likewise dimension and populate the MY matrix prompting the user for the requir
129. simpler and faster The formulas are derived from the properties of the characterictic polynomial Let s enumerate the most important ones The polynomial pA x is monic its leading coefficient is 1 and its degree is n The most important fact about the characteristic polynomial was already mentioned in the motivational paragraph the eigenvalues of A are precisely the roots of pA x The coefficients of the characteristic polynomial are all polynomial expressions in the entries of the matrix In particular its constant coefficient pA O is det A 1 n det A and the coefficient of x n 1 is tr A tr A where tr A is the matrix trace of A For a 2x2 matrix A the characteristic polynomial is therefore given by det 4 tr A A AS For a 3x3 matrix the formula specifies the characteristic polynomial to be det A cA tr A A A tr4 tr 47 where c2 is the sum of the principal minors of the matrix bo Given the above definitions it is clear now why functions MDPS and 21J J 1 will be helpful to obtain the coefficients of the characteristic polynomial for n 3 In effect when using those functions the formulas change as follows c2 MDPS xIJJI For the manual mode not as subroutine a choice is offered to see the coefficients of the polynomial before calculating its roots i e the eigenvalues Which will only take Y N as valid inputs Example 1 Calculate the eigenvalues fo
130. sion a x b x where a x 2 x 5 x 21 x 23 x 3 x 5 and b x 2 x 3 x 1 We ll use for convenience It ll store the dividend coefficients in registers R04 to R09 and the divisor s in registers R10 to R12 Note that in this case the coefficients are already there as entered in the previous example so you just have to press R S during the process The solutions are displayed sequentially starting with the quotient first The indices convention message aK X K is shown prior to the enumeration of each result polynomial After completion the control word for the reminder is left in X and the control word for the quatient is saved in ROO The solutions are q x x 4 x7 5 x 2 and r x 14 x 3 c ngel Martin August 2013 Page 69 SandMatrix 4 Manual Example 3 Calculate the addition and subtraction of the polynomials a x and b x below a x 2 x 4 x 5 x 6 and b x 2 x 3 x 7 x 1 We ll use and for convenience It ll automatically store the coefficients of the operand polynomials in registers R04 to RO7 and in registers R08 to R11 respectively The result polynomial will be stored starting with register R12 leaving the operand polynomials untouched After completion the control word for the result is left in X The solutions are a x b x 4 x x 12 x 7 a x b x 7 x 2 x 5 Below you can see the program listing for the four arithmetic driver routines 32
131. ssignment is rather simple Executing MEXP results in the following matrix 19 45828375 63 15030507 66 98787675 exp A 8 534640269 32 26024414 33 27906416 16 63953207 58 45323648 61 70173665 However trying to calculate the logarithm will not work because exp A doesnt satisfy the requirement Det exp A I 52 95249156 therefore trying on it will eventually reach an OUT OF RANGE condition Example 2 Calculate the Logarithm of the following matrix 1 2 0 1 0 3 A 0 1 0 8 0 1 0 1 0 2 0 9 In this example A I 0 5099 lt 1 thus the program will work The result matrix after executing is as follows 0 167083396 0 069577923 0 287707999 Ln A 0 097783005 0 240971674 0 103424021 0 086500972 0 235053124 0 131906636 c Angel Martin August 2013 Page 45 SandMatrix 4 Manual So we see that unfortunately the logarithm is not a trivial exercise The programs are listed below note the combination of both exponential and logarithm into a single program with flag 01 controlling the case 44 LBL 2 2 SF 01 exp flag 45 VIEW 00 3 GTO 00 46 AN 4 IBL MEXP 47 ARCL 01 5 LN flag 48 J P 49 M M 7 DIM get dimension 50 P 8 l J not square 51 CLST 9 ADV MATRX error message 52 MMOVE 10 ASTO 01 53 RCL 02 11 if al 54 FC 01 exp 12 MAT safekeeping copy 55 FACT to be used as divisor 13 DIM get dimension 56 FC 01 exp 14 p 57 GTO 04 15 MATDIM auxiliary matrix 58
132. t As one can expect from that reference it s an excellent example and therefore more that worth including in the SadnMatrix The original article is partially reproduced below it is so well described that 1 could not resist adding it practically verbatim is a small user friendly fully prompting 62 line program 124 bytes written specifically to demonstrate the excellent matrix capabilities of the Advantage ROM can find the coefficients of a polynomial of degree N which exactly fits a given set of N 1 arbitrary data points not necessarily equally spaced where N is limited only by available memory Among the many functions we could fit to data polynomials are by far the easiest to evaluate and manipulate numerically or symbolically so our problem is Given a set of n 1 data points x1 y1 xn 1 yn 1 find an Nth degree polynomial y P x al a2 x a3 x2 a4 x3 an 1 xn which includes the n 1 data points x1 y1 x2 y2 xn 1 yn 1 The coefficients al an 1 can be determined solving a system of n 1 equations 2 ii X1 Hy Ma ar wi e Ho Ha Es Jia Iv 1 JT J 1 l Rosa naa Maen ans Vues J Program listing 01 LBL POLFIT to use simply XEQ POLFIT 02 N prompts for the degree N of the polynomial 03 PROMPT and waits for the user to enter N 04 1 add 1 to get the number of data points 05 N 1 06 1 001 the required multiplier 07
133. t basically remains the same as originally written The paragraphs below are directly taken from the above reference to explain its workings This program computes all eigenvalues of a real symmetric matrix up to 22 x 22 It uses the Jacobi method which annihilates in turn selected off diagonal elements of the given matrix A using elementary orthogonal transformations in an iterative fashion until all off diagonal elements are zero when rounded to a given number of decimal places Then the diagonal values are the eigenvalues of the final matrix The method explained The Jacobi method does not attempt to solve the characteristic equation for its roots It is based in the fact that a n x n symmetric matrix has exactly n real eigenvalues Given A another matrix S can be found so that S A S D is a diagonal matrix whose elements are the eigenvalues of A The Jacobi method starts from the original matrix A and keeps on annihilating selected off diagonal elements performing elementary rotations Let s single out an off diagonal element say apq and annihilate it using an elementary rotation The transformation R is defined as follows Rpp cosz Rpq sinz Rgqp sinz Rqq cos z Ru 1 Rpk Rig Rik 0 for 1 p q and k p q Let s now denote B R AR which elements are as follows bip aip cos z diq sin z big aip sin z aiq cos z bik aik where i k p q bpp app cos z aqq sin z 2 apq sin z cos z bqq app sin z
134. t s dream for circuit analysis if this is in your area of interests you should check out the macro program written by Ted Wadman Chris Coffin and Robert Bloch as one of the proverbial three best examples of utilization of the Advantage Module Jsing Your HP HP 41 AGVENT AGE A GRAPEVINE LA ATION The program is documented in its dedicated Grapevine booklet available at http www hp41 org LibView cfm Command View amp ltemID 523 and for further convenience Jean Francois Garnier put it in ROM module format available at http www hp41 org LibView cfm Command View amp ltemID 613 Electrical o Circuits for Students The module also contains the other two famous applications y of yore 1 Electrical Circuits for Students 2 Statics for Students and 3 Computer Sicence on your HP 41 a k a the HP 16C Emulator Anybody curious enough to see what could be done with the Advantage is encouraged to check those out you ll be rewarded The last example asks you to solve a set of six simultaneous equations with six unknown variables This requires the use of MSYS as the constant matrix B s not a column matrix Example 3 Silas Farmer has the following record of sales of cabbage and broccoli forthree different weeks He knows the total weight of produce sold each week the total price received each week and the price per pound of each crop The price of cabbage is 0 24 kg and the pri
135. ternatively using the data in registers R18 R21 cnt word in Z p x 12 x 3 12x 2 5x 6 and thefore R x E x p x 009 Example 2 Calculate the partial fraction decomposition for R x below R x P x Q x x45 3 x42 1 2 The three control words returned are Z 18 021 with R18 2 3 R19 0 R10 1 9 R21 0 Y 28 031 with R29 1 9 R29 0 R30 2 9 and R31 0 X 16 017 with R16 1 9 and R17 0 The range in Y must be split as p1 2 x 9 x 0 and p2 2 2x 9 0 Therefore R x E x p1 2 x 3x 2 1 2 p2 2 x 3x 2 1 All in all a powerful program which flexibility requires some careful attention to the details involved Note you can check another Partial Fraction expansion program by Narmwon Kim available at the HP 41 archive site which features a simpler user interaction and data entry output but at the expense of more limited functionality It is also less general purpos and more geared towards control system applications http www hp41 org LibView cfm Command View amp ltemID 776 c Angel Martin August 2013 Page 89 SandMatrix 4 Manual Appendix M MCODE listings for And MROW There are a few new M Code functions in the SandMatrix that make direct usage of the module s subroutines A representative example is given below showing the very short routine LU that checks whether the matris is in its decomposed form simply by reading the approp
136. the trace of an n by n square matrix A is defined to be the sum of the elements on the main diagonal the diagonal from the upper left to the lower right of A i e Th tl where aii represents the entry on the ith row and ith column of A The trace of a matrix is the sum of the complex eigenvalues and it is invariant with respect to a change of basis Note that the trace is only defined for a square matrix i e n xn Some of the properties of the trace are quite interesting and useful for other calculations like eigenvalues and even determinants In particular one could use the relationship that defines the trace of a product of matrices tr X7TY tf enaa 2 Xi Ya If we use an identity matrix in place of Y on the equation above it s da that tr A SUM A o i where the o symbol denotes the Hadamard or entry wise product as obtained by MAT The program in the SandMath however uses a direct approach summing the elements in the diagonal it s faster and doesnt require any auxiliary matrix to hold intermediate results Eigenvalues relationships The trace of a matrix is intricately related to its eigenvalues In contrast with the determinant which is the product of its eigenvalues if A is a square n by n matrix with real or complex entries and if 1 An are the eigenvalues of A listed according to their algebraic multiplicities then tr 4 gt Xj det A IP Another powerful property rel
137. thy programs and routines on Matrix and Polynomial algebra with the specific criteria to be based on the CCD Advantage function set in an attempt to straighten the record and pay the due credit to that superb toolset that had been so underutilized 1 1 The logical next chapter after the SandMath In many respects the SandMatrix is a very conventional module There are no fancy overlays or alternate keyboards no auxiliary FATs with sub functions nor will you find dedicated function launchers a la SandMath Most of the new routines are written in FOCAL and the programs are typically large ones Programming with the Matrix functions is more about Alpha strings and auxiliary data sets than concerning with data registers and to some extent even algorithmic strategy Also because they are FOCAL programs they are slower than other areas although the 41CL has blurred the lines separating MCODE and FOCAL in terms of speed In terms of its contents it was clear from the beginning that it should be an extension to the SandMath However the dilemma was how to manage the dependencies should it be a self contained ROM or rely on functions from other modules The former option implied including many auxiliary functions in the FAT s taking precious entries and causing redundancy in the global scheme The latter option however meant a potential loss of usability since several modules were involved the Library 4 the SandMath AMC_OS X the Solve
138. tion will end Conversely if you enter more elements in the prompt than existing columns those exceeding the quota the extra ones will simply be ignored The two limitations of PMTM are as follows e A maximum length of 24 characters is possible during the prompt This includes the blank separators the comma radix and the negative signs if present e No support for the Exponential format is implemented EEX You need to use any of the other editors if your element values require such types of data Obviously this makes PMTM ithe ideal choice for matrices containing integer numbers as elements but not exclusively so as it can also be used for other values real numbers as long as the two condicions above are respected c Angel Martin August 2013 Page 37 SandMatrix 4 Manual At the heart of PMTM there is is function MROW Enter Matrix Row responsible for the presentation of the prompt in Alpha and accepting the keyboard pressings there to make up the string or list with all values It also provides the logic of actions for the control keys like ENTER Back arrow R S etc MROW is called in a loop as many times as rows exist in the matrix while ANUMDL in the SandMath is used every iteration each time a row is being processed to extract the individual element data from the global string in the prompt Below is the program listing for PMTM and as you can see it s just a sweet amp short d
139. us the combination of matrix functions to calculate the secular equation to solve for can be used in manual mode with guided prompts and data entry or in a subroutine In manual mode it creates a matrix named EV in X mem and will prompt for the elements data In subroutine mode it ll take the matrix name from Alpha You need to set flag 06 for subroutine use or clear it for manual mode this approach saves one FAT entry although requires you to be aware of the rule The program checks that the matrix is square and not in LU decomposed form presenting error and warning messages respectively For LU decomposed matrices you can double invert them on the spot assuming they re invertible and keep going just pressing R S The selection of the interval a b plays an important role in finding the solution obviously the closer to the actual value the faster it ll find it Remember also that the accuracy is determined by the display settings on the calculator so FIX 9 will provide for both the most accurate and longest execution time Example Find one eigenvalue for the matrix A below using the subroutine mode 3 1 5 A 3 3 1 464 Keystrokes Display Result ALPHA EV3 ALPHA X reg contents MNAME is in Alpha 3 003 XEQ MATDI M 3 003 Creates matrix in X Mem XEQ PMTM R1 gt Prompts for the first row 3 ENTER 1 ENTER 5 R S R2 _ second row 3 ENTER 3 ENTER 1 R S RZ
140. ves editor back to x12 R S IM1 2 4 000 The wromg imaginary part 3 R S RE2 1 x21 Correct value is entered for y 2 Proceed 4 R S IM2 1 y21 5 R S RE2 2 x22 6 R S IM2 2 y22 7 R S A I DT BSE Enters last element and returns main menu B I A I DT BSE Inverts A SHIFT A RE1 1 0 9663 Viewing A 1 2 002 A RE2 2 0 2369 Displays X22 i Y22 R S IM2 2 0 0225 R S or J A I DT BSE Exits the editor Other more advanced examples are available in the next sections of the manual during the description of the individual matrix functions c Angel Martin August 2013 Page 14 SandMatrix_4 Manual 2 2 2 Matrix Polynomial MPOL MPOL was a last minute addition to the ROM which somehow combines both matrix and polynomial algebra Use it to calculate a matrix polynomial P A not to be confused with a polynomial matrix based on an existing square matrix A and a polynomial P x P A is the result matrix calculated replacing the real variable x with A using the polynomial coefficients to multiply the different matrix powers as per the order of the polynomial terms As it s the case all throughout polynomials Honer s method proves very useful to reduce all the matrix powers to matrix multiplications with considerable execution time reduction and simplification of the code Example Calculate P A for the following matrix and polynomial P x 2x
141. with coeffs RCL 02 RCL 01 RCL 00 CROOT calculate roots FS C 06 was subroutine RTN yes end K show results ARCL Z always a real one PROMPT FC 43 complex GTO 01 no Skip prompting X lt gt Z yes clear Z CLX X lt gt Z QROUT show other two roots END done Note that in manual mode EV3X3 creates a matrix named EV but that the subroutine will work with any 3x3 matrix which name is in Alpha This is compatible with in its subroutine mode as well The roots are obtained using the SandMath function CROOT an all MCODE implementation of the Cardano Vieta formulas Function QROUT is also used to display them c ngel Martin August 2013 Page 62 SandMatrix_4 Manual General case N dimensional general matrix CHRPOL The original as it appeared in previous versions of the SandMatrix was written by Eugenio beda as published in the UPLE and later on adapted to the SandMatrix Note however that it didn t make use of any advanced Matrix function thus was pretty much the same as its initial version It was a user friendly program providing step by step guidance for the data entry and didn t require any set up preparation like creating matrices prior to the execution In this version CHRPOL has been re written from the ground up really taking advantage of the powerful matrix function set It is a much improved solution about twice as fast and with half the comparable code It
142. x name in Alpha must exist Makes aii 1 and aij 0 for i j o read E Io Om It keeps existing elements in place Output is a new matrix adds to name elements in ascending order A eee Size mxn Output is placed into X reg ill sane Zeroes clears all elements in matrix Makes aij 0 i 1 2 m j 1 2 n All elements are set to zero A few remarks on each of these functions follow as well as the program listings MAT copies an existing matrix into another with names in Alpha Prior to doing the bulk element copy it redimensions the target matrix to be the same as the source one Jt is however not required that the target matrix already already exist it will be created if not already there MCON does a simple thing converts the value in the X Reg into a matrix with all elements equal to this value This is useful in some calculations and for matrix manipulations See the simple program listings for these routines below A B expected in Alpha MNAME in Alpha 2 DIM dimension 2 MZERO clear all elements 3 ASWAP swap Alpha 3 RDN get constant back to X 4 MATDIM re dimension target 4 A prepare alpha string 5 ASWAP undo the swap 5 MAT add x to all elements 6 CLST prepare pointers 6 MNAME recall MNAME to Alpha 7 MMOVE move all elements 7 END done 8 END done c ngel Martin August 2013 Page 40 SandMatrix_4 Manual is the unsung hero behind other routines as the proper way to clear a matrix file since
143. xponent of first factor 1 R S a0 exponent of second factor 2 R S flying goose beep sounds E x informs that E x follws r aK X K Reminder of convention al 3 R S a0 1 end of data output There are three control words placed registers R05 RO6 and R15 upon completion as follows 1 The cnt l word stored in R15 is for the Quotient polynomial E x 2 The cnt word in RO5 gives the entire register range for the coefficients of all the pi x polynomials the numerators of the expanded fractions It needs to be interpreted depending on the denominators gi x are polynomials of degree 1 or polynomials pf degree 2 with negative discriminant The contents of these registers are to be read c Angel Martin August 2013 Page 88 SandMatrix_4 Manual e by groups of 1 number if deg qj 1 the numerators are constants e by groups of 2 numbers if deg qj 2 the numerators are polynomials of degree 1 e by groups of 3 numbers if deg qj 3 the numerators are polynomials of degree 2 and SO ON 3 The third in RO6 is for an alternative solution using a new reminder p x Thus in this case registers R16 and R17 contain the coefficients for E x 3x 1 And registers R33 R36 for the denominator polynomials which must be three of them p1 1 x 2x 3 p2 1 x 4 p2 2 x 5 Thus the final result is as follows R x E x p1 1 x 2x 2 x 1 p2 1 x x 2 42 p2 2 x x 2 Or al
144. your input matrix A in the MATRX program you will find only the altered decomposed form e You cannot calculate the transpose TRNPS SHIFT B in MATRX program of a matrix in LU decomposed form LU decomposition does not hinder the correct calculation of the inverse determinant or solution matrix since these operations require the LU decomposition anyway Reversing the LU Decomposition To restore a matrix to its original form from its decomposed form simply nvert it twice in effect find the inverse and then re invert to the original Naturally for this to work the matrix must be invertible non singular The result can differ slightly from the original due to rounding off during operations Editing and Viewing an LU Decomposed Matrix LU decomposed matrices are stored in a different form than normal matrices e Certain elements contain alpha data or Non normalized numbers to be precise e The matrix status register is modified to indicate that the matrix is in LU form Editing any element of the matrix will clear the LU flag in the status register which makes the matrix unrecognizable to the program Because of this if you edit one element you must edit them all if you wish to use the matrix again Note that the matrix will no longer be in LU decomposed form after this action You can view the contents of an LU decomposed matrix by doing one of the following e From the MATRX main menu press SHIFT A to view individual e

Download Pdf Manuals

image

Related Search

Related Contents

MANCHE/Enbref  VT710S VT710P  Pioneer DCS-FS30 home cinema system  vitaquick®  取付用  INSTRUCCIONES  Pour le temps préparatoire du Synode : mode d`emploi  LabelManager®  Samsung CS-29A10X1Q Инструкция по использованию  Toshiba SATELLITE L45-S7423 User Guide Manual  

Copyright © All rights reserved.
Failed to retrieve file