package pr2Calc;

/**
 * Created by khrom on 15/11/16.
 */
public class SimultaneousEquation extends Matrix {
    private double[] answers_;

    public SimultaneousEquation(double[][] input) {
        super(input);
    }

    public double[] getAnswers_() {
        return answers_;
    }

    protected void _normalize(int targetRow) {
        for (int i = targetRow; i < _getNumOfColumn(); i++) {
            m_[targetRow][i] = _getComponentOf(targetRow, i) / _getComponentOf(targetRow, targetRow);
        }
    }

    protected void _subtractRowFrom(int targetRow, int toRow) {
        for (int i = 0; i < _getNumOfColumn(); i++) {
            m_[toRow][i] = _getComponentOf(toRow, i) - _getComponentOf(targetRow, i) * _getComponentOf(toRow, i) / _getComponentOf(targetRow, i);
        }
    }


    public static void main(String[] args) {
        double[][] func = {{1, 2, 3, 4, 22}, {-3, 3, -2, 2, -14}, {6, -2, 4, -8, 8}, {3, -5, 1, 1, 23}};
        SimultaneousEquation simultaneousEquation = new SimultaneousEquation(func);
        simultaneousEquation._printMatrix();
        for (int i = 0; i < 4; i++) {
            System.out.println((i + 1) + "s1ڂ1ƂȂ悤ɊA̍s" + (i + 1) + "ڂ0ƂȂ悤Ɉ");
            simultaneousEquation._normalize(i);
            for (int j = i + 1; j < simultaneousEquation._getNumOfColumn() - 1; j++) {
                simultaneousEquation._subtractRowFrom(i, j);
            }
            simultaneousEquation._printMatrix();
        }

    }
}

@@ -220,109 +220,112 @@
  %7D%0A%0A
+%0A
     p
-ublic double%5B%5D getAnswers_() %7B%0A        return answers_;%0A    %7D%0A%0A    protected void _normalize(int
+rotected void _normalize(int targetRow) %7B%0A        final double normal = _getComponentOf(targetRow,
  tar
@@ -323,34 +323,33 @@
 tRow, targetRow)
- %7B
+;
 %0A        for (in
@@ -428,79 +428,17 @@
 %5Bi%5D 
+/
 = 
-_getComponentOf(targetRow, i) / _getComponentOf(targetRow, targetRow)
+normal
 ;%0A  
@@ -528,78 +528,21 @@
     
-for (int i = 0; i %3C _getNumOfColumn(); i++) %7B%0A            m_%5BtoRow%5D%5Bi%5D
+double divide
  = _
@@ -567,12 +567,20 @@
 ow, 
-i) -
+targetRow) /
  _ge
@@ -607,40 +607,110 @@
 ow, 
-i) * _getComponentOf(toRow, i) /
+targetRow);%0A        for (int i = 0; i %3C _getNumOfColumn(); i++) %7B%0A            m_%5BtoRow%5D%5Bi%5D -= divide *
  _ge
@@ -758,272 +758,142 @@
  %7D%0A%0A
-%0A
     
-public static void main(String%5B%5D args) %7B
+/**%0A     * KEXW_%CC%8F@g%C4%8CvZ%E9%83%81%5Cbh
 %0A    
+ */%0A
     
-double%5B%5D%5B%5D func = %7B%7B1, 2, 3, 4, 22%7D, %7B-3, 3, -2, 2, -14%7D, %7B6, -2, 4, -8, 8%7D, %7B3, -5, 1, 1, 23%7D%7D;%0A        SimultaneousEquation simultaneousEquation = new SimultaneousEquation(func);%0A        simultaneousEquation.
+public void _solveByGaussJordan() %7B%0A        answers_ = new double%5B_getNumOfRow()%5D;%0A        
 _pri
@@ -936,9 +936,22 @@
 i %3C 
-4
+_getNumOfRow()
 ; i+
@@ -998,17 +998,31 @@
  1) + %22s
-1
+%22 + (i + 1) + %22
 %DA%821%C6%82%C8%82%E6%82%A4%C9%8AA%CC%8D
@@ -1059,37 +1059,16 @@
         
-simultaneousEquation.
 _normali
@@ -1103,204 +1103,867 @@
 j = 
-i + 1; j %3C simultaneousEquation._getNumOfColumn() - 1; j++) %7B%0A                simultaneousEquation._subtractRowFrom(i, j);%0A            %7D%0A            simultaneousEquation._printMatrix();%0A        %7D%0A
+0; j %3C _getNumOfRow(); j++) %7B%0A                if (i != j) _subtractRowFrom(i, j);%0A            %7D%0A            _printMatrix();%0A        %7D%0A%0A        for (int i = 0; i %3C _getNumOfRow(); i++) %7B%0A            answers_%5Bi%5D = _getComponentOf(i, _getNumOfColumn() - 1);%0A        %7D%0A        System.out.println(%22Answer:%22);%0A        for (int i = 0; i %3C _getNumOfRow(); i++) %7B%0A            if (i != 0) System.out.print(%22, %22);%0A            System.out.print(%22x%22 + (i + 1) + %22=%22 + String.format(%22%251$4.1f%22, answers_%5Bi%5D));%0A%0A        %7D%0A%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        double%5B%5D%5B%5D func = %7B%0A                %7B2, 1, 3, 4, 2%7D,%0A                %7B3, 2, 5, 2, 12%7D,%0A                %7B3, 4, 1, -1, 4%7D,%0A                %7B-1, -3, 1, 3, -1%7D%7D;%0A        SimultaneousEquation simultaneousEquation = new SimultaneousEquation(func);%0A        simultaneousEquation._solveByGaussJordan();
 %0A   

kadai5