///////////////////////////////////////////////////////////////////////////////////////////// // // GaussJordan.java // Runs Gauss Jordan Elimination on a matrix // // 1. Save this file as GaussJordan.java on any system with the javac compiler, available // from Sun Microsystems: http://java.sun.com/javase/downloads/index.jsp // 2. If you're on a unix system also save the file "Makefile" in the same directory, then // 3. Compile by typing "make" or "gmake" at the command line (leave out the quotes). // 4. Run the executable by doing "GaussJordan infile outfile", where "infile" is // a properly formated (described below) input file. // 5. Else if you're on any other system, then // 6. Compile by typing "javac GaussJordan.java" at the command line (leave out quotes). // 7. Run the executable by doing "java GaussJordan infile outfile, where "infile" is // a properly formated (described below) input file. // // Note: if "outfile" already exists in your working directory, then the above commands will // overwrite it. // // Input file format. // The first line of an input file consists of two integers n and m, separated by a space, // giving the number of rows and columns, respectively. The next n lines of the input file // specify the n rows of the matrix. Each line is a space separated list of m real numbers. // Note that the number of spaces separating the numbers in each row is irrelevant. // // Example 1 (Save the following lines as a text file called in1.) // 3 5 // 2 0 4 2 9 // 3 4 0 0 -7 // 0 1 0 5 0 // // Example 2 (Save as text file in2.) // 4 7 // 3.1 4.2 7.9 0.0 0.0 1.1 8.2 // -6.7 1.2 3.4 5.6 7.8 0.0 0.0 // 9.8 7.6 5.4 3.2 2.1 2.3 4.5 // 6.7 8.8 -9.1 2.5 3.6 4.7 -5.5 // ///////////////////////////////////////////////////////////////////////////////////////////// import java.io.*; import java.util.StringTokenizer; class GaussJordan{ // swap() // swap row i with row k // pre: A[i][q]==A[k][q]==0 for 1<=q