///////////////////////////////////////////////////////////////////////////////////////////// // // Basis.java // Determines bases for the image and kernal of a matrix // // Save this file as Basis.java on any system with the javac compiler, available // from Sun Microsystems: http://java.sun.com/javase/downloads/index.jsp // If you're on a unix system also save the file "Makefile" in the same directory, then // Compile by typing "make" or "gmake" at the command line (leave out the quotes). // Run the executable by doing "Basis infile outfile", where "infile" is // a properly formated (described below) input file. // If you're on any other system, then // Compile by typing "javac Basis.java" at the command line (leave out quotes). // Run the executable by doing "java Basis 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 // // Output file format. // The output will consist of three matrices. The input matrix (nxm) will be reprinted, // followed by a matrix with n rows and r columns, where r is the rank of the input matrix. // This second matrix will consist of a subset of the columns of the input matrix which // form a basis for it's image. The third matrix will have m rows and m-r columns, which // form a basis for the kernal of the input matrix. The format of the matrix entries can // be adjusted by changing the vaules of the constants PRECISION and COLUMN_WIDTH below // (lines 60 and 61 of this file). PRECISION specifies the number of decimal digits to // the right of the decimal point (default 3), and COLUMN_WIDTH gives the minimum number // of characters to be printed in each column (default 10). If the number printed exceeds // this width, the field will expand to accomodate the extra characters. There is a // further space included after each column. After changing these constants, you must // recompile the program. // ///////////////////////////////////////////////////////////////////////////////////////////// import java.io.*; import java.util.StringTokenizer; class Basis{ static final int PRECISION = 3; static final int COLUMN_WIDTH = 10; // swap() // swap row i with row k // pre: A[i][q]==A[k][q]==0 for 1<=q