// ComplexMatrix.java // solve, invert, etc. last argument is output // void solve(Complex A[][], Complex Y[], Complex X[]); X=A^-1*Y // void invert(Complex A[][]); A=A^-1 // Complex determinant(Complex A[]); d=det A // void eigenvalues(Complex A[][], ComplexV[][], Complex Y[]); V,Y=eigen A // void eigenCheck(Complex A[][], V[][], Complex Y[]); printout // void multiply(Complex A[][], Complex B[][], Complex C[][]); C=A*B // void add(Complex A[][], Complex B[][], Complex C[][]); C=A+B // void subtract(Complex C[][], Complex A[][], complex B[][]); C=A-B // double norm1(Complex A[][]); d=norm1 A // double norm2(Complex A[][]); sqrt largest eigenvalue A^T*A d=norm2 A // double normFro(Complex A[][]); Frobenius d=normFro A // double normInf(Complex A[][]); d=normInf A // void copy(Complex A[][], Complex B[][]); B=A // void boolean equals(Complex A[][], Complex B[][]); A==B // void fromDouble(double A[], double b[][], Complex C[][]); C=(A,b) // void fromDouble(double A[], Complex B[][]); B=A // void identity(A[][]); A=I // void zero(A[][]); A=0 // void print(Complex A[][]); A // void multiply(Complex A[][], Complex X[], Complex Y[]); Y=A*X // void add(Complex X[], Complex Y[], Complex Z[]); Z=X+Y // void subtract(Complex X[], Complex Y[], Complex Z[]); Z=X-Y // double norm1(Complex X[]); d=norm1 X // double norm2(Complex X[]); d=norm2 X // double normInf(Complex X[]); d=normInf X // void copy(Complex X[], Complex Y[]); Y=X // void boolean equals(Complex X[], Complex Y[]); X==Y // void fromDouble(double X[], double Y[], Complex Z[]); Z=(X,Y) // void fromDouble(double X[], Complex Y[]); Y=(X,0) // void unitVector(X[],I); X[I]=1, else 0 // void zero(X[]); X=0 // void print(Complex X[]); X // void readSize(String, rowCol[]) // void read(String, Complex[][]) // void closeInput() // void write(String, Complex[][]) // void closeOutput() import java.io.*; public strictfp class ComplexMatrix { public static void solve(final Complex A[][], final Complex Y[], Complex X[]) { // solve complex linear equations for X where Y = A * X // method: Gauss-Jordan elimination using maximum pivot // usage: ComplexMatrix.solve(A,Y,X); // Translated to java by : Jon Squire , 4 April 2003 // First written by Jon Squire December 1959 for IBM 650, translated to // other languages e.g. Fortran converted to Ada converted to C // converted to java int n=A.length; int m=n+1; Complex B[][]=new Complex[n][m]; // working matrix int row[]=new int[n]; // row interchange indicies int hold , I_pivot; // pivot indicies Complex pivot; // pivot element value double abs_pivot; if(A[0].length!=n || Y.length!=n || X.length!=n) { System.out.println("Error in ComplexMatrix.solve,"+ " inconsistent array sizes."); } // build working data structure for(int i=0; i abs_pivot) { I_pivot = i; pivot = B[row[i]][k]; abs_pivot = pivot.abs(); } } // have pivot, interchange row indicies hold = row[k]; row[k] = row[I_pivot]; row[I_pivot] = hold; // check for near singular if(abs_pivot < 1.0E-10) { for(int j=k+1; j abs_pivot) { I_pivot = i ; J_pivot = j ; pivot = A[row[i]][col[j]] ; } } } if(pivot.abs() < 1.0E-10) { System.out.println("ComplexMatrix is singular !"); return; } hold = row[k]; row[k]= row[I_pivot]; row[I_pivot] = hold ; hold = col[k]; col[k]= col[J_pivot]; col[J_pivot] = hold ; // reduce about pivot A[row[k]][col[k]] = (new Complex(1.0,0.0)).divide(pivot) ; for(int j=0; j abs_pivot ) { I_pivot = i; pivot = B[row[i]][k]; abs_pivot = pivot.abs(); } } // have pivot, interchange row indicies if(I_pivot != k) { hold = row[k]; row[k] = row[I_pivot]; row[I_pivot] = hold; D = D.negate(); } // check for near singular if(abs_pivot < 1.0E-10) { return new Complex(0.0,0.0); } else { D = D.multiply(pivot); // reduce about pivot for(int j=k+1; j=0.0) t=tau.add(tau_tau_1).invert(); else t=(tau_tau_1.subtract(tau)).invert().negate(); c=(t.multiply(t)).add(1.0).sqrt().invert(); s=t.multiply(c); } else { c=new Complex(1.0,0.0); s=new Complex(0.0,0.0); } } // end schur2 static void mat22(final Complex c, final Complex s, final Complex A[][], Complex B[][]) { if(A.length!=2 || A[0].length!=2 || B.length!=2 || B[0].length!=2) { System.out.println("Error in mat22 of Jacobi, not both 2 by 2"); } Complex T[][] = new Complex[2][2]; T[0][0] = c.multiply(A[0][0]).subtract(s.multiply(A[0][1])); T[0][1] = s.multiply(A[0][0]).add (c.multiply(A[0][1])); T[1][0] = c.multiply(A[1][0]).subtract(s.multiply(A[1][1])); T[1][1] = s.multiply(A[1][0]).add (c.multiply(A[1][1])); B[0][0] = c.multiply(T[0][0]).subtract(s.multiply(T[1][0])); B[0][1] = c.multiply(T[0][1]).subtract(s.multiply(T[1][1])); B[1][0] = s.multiply(T[0][0]).add (c.multiply(T[1][0])); B[1][1] = s.multiply(T[0][1]).add (c.multiply(T[1][1])); } // end mat2 static void mat44(final int p, final int q, final Complex c, final Complex s, final Complex A[][], Complex V[][]) { int n = A.length; Complex B[][] = new Complex[n][n]; Complex J[][] = new Complex[n][n]; if(A[0].length!=n || V.length!=n || V[0].length!=n) { System.out.println("Error in mat44 of Complex Jacobi,"+ " A or V not same and square"); } for(int i=0; i