/** Creates a new instance of testmatrix */ public GLSsolver(double[][] p_MatrixgleichNull) throws IllegalArgumentException { // -------------------------------------- // Kontrolle, ob Eingabematrix rechteckig // -------------------------------------- int nplus1 = p_MatrixgleichNull[0].length; for (int i = 1; i < p_MatrixgleichNull.length; i++) { // Zeilen i if (p_MatrixgleichNull[i].length != nplus1) { System.err.println( "Programmfehler: Matrix des GLS ist nicht rechteckig! (im solver entdeckt)"); throw new IllegalArgumentException(); } } if (nplus1 <= 1) throw new IllegalArgumentException("keine Unbekannte"); // keine Unbekannte!!! // Umgeht einen Fehler in der colt-Bibliothek // TODO wenn behoben, Workaround entfernen // ------ int anzGl = p_MatrixgleichNull.length; if (anzGl < nplus1 - 1) { // anzGleichungen < anz Unbekannte if (debug) System.out.println("WorkAround fuer Fehler in colt: 0 = 0 Gleichungen anhaengen"); anzGl = nplus1 - 1; // = Anzahl Unbek, 0 0 0 ... 0 = 0 Zeile angehängt } // ------------------------- // Daten in A und b einlesen // ------------------------- // so dass A*x = b A = new DenseDoubleMatrix2D(anzGl, (nplus1 - 1)); DenseDoubleMatrix2D b = new DenseDoubleMatrix2D(anzGl, 1); for (int i = 0; i < p_MatrixgleichNull.length; i++) { // Zeilen i for (int j = 0; j < nplus1 - 1; j++) { // Spalten A.set(i, j, p_MatrixgleichNull[i][j]); } b.set(i, 0, -p_MatrixgleichNull[i][nplus1 - 1]); } if (debug) { System.out.println(" A = " + A.toString()); System.out.println(" b = " + b.toString()); System.out.println(""); } // -------------- // LR - Zerlegung // -------------- LUDecomposition ALU = new LUDecomposition(A); if (debug) System.out.println(ALU.toString()); DoubleMatrix2D L = ALU.getL(); R = ALU.getU(); int[] piv = ALU.getPivot(); Algebra alg = new Algebra(); // if (debug) System.out.println("L = " + L.toString()); // if (debug) System.out.println("Kontrolle L*R = " + alg.mult(L,R).toString()); // if (debug) System.out.println("Kontrolle P*b = " + alg.permute(b, piv, null) ); // // if (debug) System.out.println("Rx = c: R = " + R.toString()); // if (debug) System.out.println("alg.permute(b, piv, null) = " + alg.permute(b, piv, // null).toString()); c = alg.solve(L, alg.permute(b, piv, null)); // TODO: kann zu Problemen führen, // wenn weniger Gleichungen als Unbek --> s.Workaround oben if (debug) System.out.println("Lc = Pb: c = " + c.toString()); if (debug) { System.out.println("Rang A: " + alg.rank(A)); System.out.println("Rang R: " + alg.rank(R)); } assert (alg.rank(A) == alg.rank(R)) : "Rang von A ungleich Rang von R --> Programmfehler"; anzUnbestParam = A.columns() - alg.rank(A); if (debug) System.out.println("Anz unbest Parameter: " + anzUnbestParam); }