# TITLE: Matrix Inverse by Gaussian Elimination 1.2 # AUTHOR: Roy F.A. Maclean # based on my gaussian elimination program which was in turn based on # algorithm in Adv.Eng.Maths. (7th ed) by E.Kreyzig # EMAIL: rfamgm at gmail # WEB: http://www.spiderpixel.co.uk/caspro # DATE: 26Jun2007 # MAKE: CASIO # MODEL: 9850 # # NOTES: # # There are two version of this program below, # # For the first version - enter an NxN matrix into Mat A, # # this program will display step-by-step row operations required to find the inverse, # it uses Mat C to work on and stores the inverse in Mat B, leaving Mat A untouched. # # For the second version you can enter an NxN matrix or an NxN+1 augmented matrix. # If you enter an NxN+1 matrix then the solution will also be displayed. # # _ is the triangle disp symbol on the pgrm menu # % is the fraction button [ab/c] @@ Program "INVGAUSS" Lbl 0 Dim Mat A List Ans[1->A List Ans[2->B A<>B=>"MATRIX IS NOT SQUARE" A<>B=>Goto 0 Identity A->Mat B "INITIAL MATRIX"_ Mat A->Mat C_ For 1->K To A-1 For K->J To A Mat C[J,K]<>0=>Break Next A=1=>1->J Mat C[J,K]=0=>Goto 9 A=1=>Goto 8 If J<>K Then ClrText Locate 1,2,"SWAPPING ROWS" Locate 1,3,K Locate 1,4,"AND" Locate 1,5,J_ Swap C,J,K Swap B,J,K Mat C_ ClrText:"I"_ Mat B_ IfEnd For K+1->J To A -Mat C[J,K]%Mat C[K,K->H If H<>0 Then ClrText Locate 1,2,"ADDING" Locate 1,3,H Locate 1,4,"TIMES ROW" Locate 1,5,K Locate 1,6,"TO ROW" Locate 1,7,J_ *Row+ H,C,K,J *Row+ H,B,K,J Mat C_ ClrText:"I"_ Mat B_ IfEnd Next Next Lbl 8 Mat C[A,A]->M M=0=>Goto 9 For A->C To 1 Step (-)1 Mat C[C,C]->M If M<>1 Then 1->Mat C[C,C] *Row 1%M,B,C ClrText Locate 1,2,"MULTIPLYING ROW" Locate 1,3,C Locate 1,4,"BY" Locate 1,5,1%M_ Mat C_ ClrText:"I"_ Mat B_ IfEnd For C-1->R To 1 Step (-)1 (-)Mat C[R,C]->H If H<>0 Then *Row+ H,B,C,R 0->Mat C[R,C] ClrText Locate 1,2,"ADDING" Locate 1,3,H Locate 1,4,"TIMES ROW" Locate 1,5,C Locate 1,6,"TO ROW" Locate 1,7,R_ Mat C_ ClrText:"I"_ Mat B_ IfEnd Next Next "THE INVERSE IS"_ Mat B_ Lbl 1 "PRESS AC TO STOP"_ Goto 1 Lbl 9 ClrText "NOT INVERTIBLE"_ Goto 9 @@ Program "INVGAUS2" Lbl 0 Dim Mat A List Ans[1->A List Ans[2->B If A<>B And B<>A+1 Then "MATRIX IS NOT SQUARE N*N OR AUGMENTED N*N+1"_ Goto 0 IfEnd "INITIAL MATRIX"_ If B=A+1 Then For 1->C To B Mat->List(Mat A,C)->List 1 List->Mat(List 1) C=1=>Mat Ans->Mat C C>1=>CAugment(Mat C,Mat Ans)->Mat C C=B=>Mat Ans->Mat D Next Mat C_ Else Mat A->Mat C_ IfEnd Identity A->Mat B For 1->K To A-1 For K->J To A Mat C[J,K]<>0=>Break Next A=1=>1->J Mat C[J,K]=0=>Goto 9 A=1=>Goto 8 If J<>K Then ClrText Locate 1,2,"SWAPPING ROWS" Locate 1,3,K Locate 1,4,"AND" Locate 1,5,J_ Swap C,J,K Swap B,J,K Mat C_ ClrText:"I"_ Mat B_ IfEnd For K+1->J To A -Mat C[J,K]%Mat C[K,K->H If H<>0 Then ClrText Locate 1,2,"ADDING" Locate 1,3,H Locate 1,4,"TIMES ROW" Locate 1,5,K Locate 1,6,"TO ROW" Locate 1,7,J_ *Row+ H,C,K,J *Row+ H,B,K,J Mat C_ ClrText:"I"_ Mat B_ IfEnd Next Next Lbl 8 Mat C[A,A]->M M=0=>Goto 9 For A->C To 1 Step (-)1 Mat C[C,C]->M If M<>1 Then 1->Mat C[C,C] *Row 1%M,B,C ClrText Locate 1,2,"MULTIPLYING ROW" Locate 1,3,C Locate 1,4,"BY" Locate 1,5,1%M_ Mat C_ ClrText:"I"_ Mat B_ IfEnd For C-1->R To 1 Step (-)1 (-)Mat C[R,C]->H If H<>0 Then *Row+ H,B,C,R 0->Mat C[R,C] ClrText Locate 1,2,"ADDING" Locate 1,3,H Locate 1,4,"TIMES ROW" Locate 1,5,C Locate 1,6,"TO ROW" Locate 1,7,R_ Mat C_ ClrText:"I"_ Mat B_ IfEnd Next Next "THE INVERSE IS"_ Mat B_ Dim Mat A List Ans[1]->A List Ans[2]->B If B=A+1 Then "THE SOLN IS"_ Mat BMat D_ IfEnd Lbl 1 "PRESS AC TO STOP"_ Goto 1 Lbl 9 ClrText "NOT INVERTIBLE"_ Goto 9