/** * BMatrix.java -- manipulate square matrices * * By Bob Jenkins, October 1999 * Permission granted to use, reuse, rewrite this without notifying me. */ // A square matrix, built out of vectors // Assumes that all matrices vectors are of the same length. final public class BMatrix { BVector d[]; // array of vectors // make a matrix of size length x length initialized to zero BMatrix(int length) { d = new BVector[length]; for (int i=0; i0.0) ? d[j].c[j] : -d[j].c[j]); int r = j; for (int i=j+1; i0.0) ? d[i].c[j] : -d[i].c[j])) > max) { max = temp; r = i; } } // raise an error if matrix is not invertible if (max == 0.0) { System.out.println("Singular matrix! No inverse!"); System.out.println(toString()); return; } // row interchange if (r > j) { BVector temp=d[j]; d[j]=d[r]; d[r]=temp; int tempi = p[j]; p[j]=p[r]; p[r]=tempi; } // transformation double hr = 1.0/d[j].c[j]; for (int i=0; i