# TITLE: Gaussian Elimination 7400 # 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: 21Jul2007 # MAKE: CASIO # MODEL: 7400 # NOTES: This program is used to solve a # system of n linear equations in n unknowns. # Put the entries of the augmented NxN+1 matrix into List 1 row by row. # Then run the program. # The program will say which row operations it uses # and will display List 2 at each stage. # List 2 represents the matrix at intermediate stages. # The initial matrix in List 1 remains unchanged. # 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 entries into List 1 # 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. # Finally it displays: # "THE SOLN IS" and then # 1 # 5 # 6 # which means that the soln is x=1, y=5, z=6 # # % represents the fraction symbol [ab/c] # _ represents the display symbol: [SHIFT][VARS][>][F2] # # # 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 ClrText "ROWS"?->A A+1->B Dim List 1 If Ans<>AB Then "LIST 1 DOES" "NOT CONTAIN" "N*(N+1)" "ENTRIES"_ IfEnd Ans<>AB=>Goto 0 Seq(0,X,1,A,1->List 3 "INITIAL" "MATRIX"_ List 1->List 2 List 2_ For 1->K To A-1 For K->J To A List 2[(J-1)B+K]<>0=>Break Next A=1=>1->J List 2[(J-1)B+K]=0=>Goto 9 A=1=>Goto 8 If J<>K Then ClrText "SWAPPING ROWS" K_ "AND" J_ For 1->C To N+1 List 2[(K-1)B+C]->D List 2[(J-1)B+C]->List 2[(K-1)B+C] D->List 2[(J-1)B+C] Next List 2_ IfEnd For K+1->J To A -List 2[(J-1)B+K]%List 2[(K-1)B+K->H If H<>0 Then ClrText "ADDING" H_ "TIMES ROW" K_ "TO ROW" J_ For 1->C To N+1 HList 2[(K-1)B+C]+List 2[(J-1)B+C]->List 2[(J-1)B+C] Next List 2_ IfEnd Next Next Lbl 8 ClrText "ELIMINATION" "COMPLETE"_ List 2_ List 2[(A-1)B+A]->M M=0=>Goto 9 List 2[(A-1)B+A+1]%M->List 3[A A=1=>Goto 7 For A-1->E To 1 Step -1 0->D For E+1->C To A List 3[C]List 2[(E-1)B+C]+D->D Next (List 2[(E-1)B+A+1]-D)%List 2[(E-1)B+E->List 3[E Next Lbl 7 ClrText "THE SOLN IS"_ List 3_ Goto 0 Lbl 9 ClrText "NO UNIQUE" "SOLN"_ Goto 0