# TITLE: Gaussian Elimination v1.3:9850 # AUTHOR: Roy F.A. Maclean # based on the algorithm in Adv.Eng.Maths. (7th ed) by E.Kreyzig # EMAIL: rfamgm at gmail # WEB: http://www.spiderpixel.co.uk/caspro # DATE: 3Apr1996, 16Feb1997, 28Sep1999 # MAKE: CASIO # MODEL: 9850 # NOTES: This program is used to solve a # system of n linear equations in n unknowns. # Put the augmented NxN+1 matrix into matrix A. # Then run the program. # The program will say which row operations it uses # and display the matrix at each stage. # Finally it will display the soln. # # e.g. to solve: # x + y+ z =12 # 2x+2y+ z =18 # x -3y+2z =-2 # Put the following matrix into matrix A # 1 1 1 12 # 2 2 1 18 # 1 -3 2 -2 # Then run the program. # Various messages will appear to say which rows # it adds to which other rows and which ones it is swapping. # Then it displays the matrix: # [ 1 5 6 ] # which means that the soln is x=1, y=5, z=6 # # % represents the fraction symbol # _ represents the display symbol: shift|vars|f5 # List->Mat( is on optn|f1|f2 # # On models with autodimensioning capability # such as 9850GB+ and 9970G then replace the lines # between the apostrophes with: # {1,A}->Dim Mat B # # # Notes for programmers: # # Although you might think single row input matrix making A=1 # would cause errors with nested 'For' loops it doesn't because although # the first 'For' loop exits out at the wrong 'Next' command from the # point of view of the way 'For' loops ought to work, it never sees # the correct 'Next' because of the A=1=>Goto 8, and so never # causes an error. So in this case two wrongs make a right. @@ Program "GAUSELIM" Lbl 0 Dim Mat A List Ans[1->A List Ans[2->B B<>A+1=>"MATRIX IS NOT IN AUGMENTED FORM N*(N+1)" B<>A+1=>Goto 0 ' Seq(0,X,1,A,1->List 1 List->Mat(List 1) Trn Mat Ans->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 Mat C_ 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 Mat C_ IfEnd Next Next Lbl 8 ClrText "ELIMINATION COMPLETE"_ Mat C_ Mat C[A,A]->M M=0=>Goto 9 Mat C[A,A+1]%M->Mat B[1,A A=1=>Goto 7 For A-1->E To 1 Step -1 0->D For E+1->C To A Mat B[1,C]Mat C[E,C]+D->D Next (Mat C[E,A+1]-D)%Mat C[E,E->Mat B[1,E Next Lbl 7 "THE SOLN IS"_ Mat B_ Goto 0 Lbl 9 "NO UNIQUE SOLN" Goto 0