From 0c0c9a8f61572a795ca630bb87cd82eb971c3587 Mon Sep 17 00:00:00 2001 From: Anton Klimov Date: Tue, 11 Dec 2018 23:37:33 +0700 Subject: [PATCH 01/10] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B2=20=D0=BC=D0=BE=D0=BD=D0=BE=D0=BB=D0=B8=D1=82=D0=BD=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20GuassianElimint?= =?UTF-8?q?ation=20=D0=BF=D0=BE=D0=B7=D0=B6=D0=B5=20=D0=BE=D0=BD=20=D0=B1?= =?UTF-8?q?=D1=83=D0=B4=D0=B5=D1=82=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D1=91?= =?UTF-8?q?=D0=BD=20=D0=BF=D0=BE=D0=B4=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D1=91?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=BE=D0=B4=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=20=D1=81=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC=20Row,=20Matrix=20=D0=B8?= =?UTF-8?q?=20LinearEquation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 20 +++++ .../GaussianElimintation.java | 80 +++++++++++++++++++ .../GaussianElimintation/LinearEquation.java | 33 ++++++++ src/main/java/GaussianElimintation/Main.java | 7 ++ .../java/GaussianElimintation/Matrix.java | 26 ++++++ src/main/java/GaussianElimintation/Row.java | 47 +++++++++++ src/main/java/SystemWith2Variables.java | 24 ++++++ src/test/java/GuassianElimintationTest.java | 16 ++++ 8 files changed, 253 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/GaussianElimintation/GaussianElimintation.java create mode 100644 src/main/java/GaussianElimintation/LinearEquation.java create mode 100644 src/main/java/GaussianElimintation/Main.java create mode 100644 src/main/java/GaussianElimintation/Matrix.java create mode 100644 src/main/java/GaussianElimintation/Row.java create mode 100644 src/main/java/SystemWith2Variables.java create mode 100644 src/test/java/GuassianElimintationTest.java diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..17be857 --- /dev/null +++ b/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + hyperskill + ru.jnster + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + test + + + + \ No newline at end of file diff --git a/src/main/java/GaussianElimintation/GaussianElimintation.java b/src/main/java/GaussianElimintation/GaussianElimintation.java new file mode 100644 index 0000000..d288279 --- /dev/null +++ b/src/main/java/GaussianElimintation/GaussianElimintation.java @@ -0,0 +1,80 @@ +package GaussianElimintation; + +public class GaussianElimintation { + private double matrix[][]; + private double result[]; + private int N; + + public GaussianElimintation(double[][] matrix) { + setMatrix(matrix); + } + + private double[] findAnswer() { + double coefficient; + result = new double[N--]; + for (int counter = 0; counter < N; counter++) { + for (int next = counter + 1; next <= N; next++) { + coefficient = matrix[next][counter] / matrix[counter][counter] * -1; + add(coefficient, matrix[counter], matrix[next], counter); + } + } + for (int counter = N; counter >= 0; counter--) { + result[counter] = (matrix[counter][N + 1] - calculate(counter)) / matrix[counter][counter]; + } + return result; + } + + private double[] add(double[] what, double[] to, int skipFirst) { + return add(1, what, to, skipFirst); + } + + private double[] add(double[] what, double[] to) { + return add(1, what, to, 0); + } + + private double[] add(double coefficient, double[] what, double[] to, int skipFirst) { + for (int counter = skipFirst; counter <= N + 1; counter++) { + to[counter] += what[counter] * coefficient; + } + return to; + } + + public static boolean isSquareMatrix(double[][] matrix) { + boolean result = true; + int N = matrix.length; + for (double[] line : matrix) { + result &= line.length == N + 1; + } + return result; + } + + private double calculate(int stage) { + double result = 0.0; + if (stage != N) { + for (int counter = stage + 1; counter <= N; counter++) { + result += matrix[stage][counter] * this.result[counter]; + } + } + return result; + } + + public void setMatrix(double[][] matrix) { + try { + if (!isSquareMatrix(matrix)) throw new RuntimeException("This matrix is not square matrix."); + } catch (RuntimeException re) { + re.printStackTrace(); + } + this.matrix = matrix; + N = this.matrix.length; + result = null; + } + + public double[][] getMatrix() { + return matrix; + } + + public double[] getResult() { + if (result == null) result = findAnswer(); + return result; + } +} diff --git a/src/main/java/GaussianElimintation/LinearEquation.java b/src/main/java/GaussianElimintation/LinearEquation.java new file mode 100644 index 0000000..538006b --- /dev/null +++ b/src/main/java/GaussianElimintation/LinearEquation.java @@ -0,0 +1,33 @@ +package GaussianElimintation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class LinearEquation { + protected List coefficients = new ArrayList(); + protected Double rightSide; + + public LinearEquation(Double rightSide, Double... coefficients) { + this.rightSide = rightSide; + this.coefficients.addAll(Arrays.asList(coefficients)); + } + + public LinearEquation(Double[] array) { + this(array[array.length - 1], Arrays.copyOf(array, array.length - 1)); + } + + public Row toRow() { + List buffer = new ArrayList(coefficients); + buffer.add(rightSide); + return new Row((Double[]) buffer.toArray()); + } + + public List getCoefficients() { + return coefficients; + } + + public void setCoefficients(List coefficients) { + this.coefficients = coefficients; + } +} diff --git a/src/main/java/GaussianElimintation/Main.java b/src/main/java/GaussianElimintation/Main.java new file mode 100644 index 0000000..ee6a7c6 --- /dev/null +++ b/src/main/java/GaussianElimintation/Main.java @@ -0,0 +1,7 @@ +package GaussianElimintation; + +public class Main { + public static void main(String[] args) { + + } +} diff --git a/src/main/java/GaussianElimintation/Matrix.java b/src/main/java/GaussianElimintation/Matrix.java new file mode 100644 index 0000000..4aab135 --- /dev/null +++ b/src/main/java/GaussianElimintation/Matrix.java @@ -0,0 +1,26 @@ +package GaussianElimintation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +public class Matrix { + protected List rows; + + public Matrix(Row... rows) { + this.rows = new ArrayList(Arrays.asList(rows)); + } + + public Matrix(Collection rows) { + this.rows = new ArrayList(rows); + } + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } +} diff --git a/src/main/java/GaussianElimintation/Row.java b/src/main/java/GaussianElimintation/Row.java new file mode 100644 index 0000000..bfb2771 --- /dev/null +++ b/src/main/java/GaussianElimintation/Row.java @@ -0,0 +1,47 @@ +package GaussianElimintation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Row { + protected List doubleList; + + public Row(Double... array) { + doubleList = new ArrayList<>(Arrays.asList(array)); + } + + public Row(LinearEquation linearEquation) { + doubleList = new ArrayList<>(linearEquation.coefficients); + doubleList.add(linearEquation.rightSide); + } + + public void add(Row row) { + add(row, 1, 0); + } + + public void add(Row row, double coefficient) { + add(row, coefficient, 0); + } + + public void add(Row row, double coefficient, int skipFirst) { + Double[] to = (Double[]) doubleList.toArray(), + what = (Double[]) row.doubleList.toArray(); + for (int counter = skipFirst; counter < doubleList.size(); counter++) { + to[counter] += what[counter] * coefficient; + } + doubleList = new ArrayList<>(Arrays.asList(to)); + } + + public LinearEquation toLinearEquation() { + return new LinearEquation((Double[]) doubleList.toArray()); + } + + public List getDoubleList() { + return doubleList; + } + + public void setDoubleList(List doubleList) { + this.doubleList = doubleList; + } +} diff --git a/src/main/java/SystemWith2Variables.java b/src/main/java/SystemWith2Variables.java new file mode 100644 index 0000000..e19974e --- /dev/null +++ b/src/main/java/SystemWith2Variables.java @@ -0,0 +1,24 @@ +import java.util.Scanner; + +public class SystemWith2Variables { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + double a, + b, + c, + d, + f, + e, + y, + x; + a = sc.nextDouble(); + b = sc.nextDouble(); + c = sc.nextDouble(); + d = sc.nextDouble(); + e = sc.nextDouble(); + f = sc.nextDouble(); + y = (f - c * d / a) / (e - b * d / a); + x = (c - b * y) / a; + System.out.println(x + " " + y); + } +} diff --git a/src/test/java/GuassianElimintationTest.java b/src/test/java/GuassianElimintationTest.java new file mode 100644 index 0000000..f51e7ee --- /dev/null +++ b/src/test/java/GuassianElimintationTest.java @@ -0,0 +1,16 @@ +import GaussianElimintation.GaussianElimintation; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + +public class GuassianElimintationTest { + @Test + public void simpleTest() { + double matrix[][] = {{1.0, 1.0, 2.0, 9.0}, {2.0, 4.0, -3.0, 1.0}, {3.0, 6.0, -5.0, 0.0}}; + double result[] = {1.0, 2.0, 3.0}; + GaussianElimintation gaussianElimintation = new GaussianElimintation(matrix); + Assert.assertTrue(Arrays.equals(result, gaussianElimintation.getResult())); + } + +} From b2ac507a0ee78174f15d1a401fd2c0daac3d3435 Mon Sep 17 00:00:00 2001 From: Anton Klimov Date: Sat, 15 Dec 2018 01:04:07 +0700 Subject: [PATCH 02/10] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D1=91=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D1=85=D0=BE=D0=B4=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GaussianElimintation.java | 64 +++++++++++-------- .../java/GaussianElimintation/Matrix.java | 63 ++++++++++++++++-- src/main/java/GaussianElimintation/Row.java | 18 +++++- 3 files changed, 112 insertions(+), 33 deletions(-) diff --git a/src/main/java/GaussianElimintation/GaussianElimintation.java b/src/main/java/GaussianElimintation/GaussianElimintation.java index d288279..8cfba3b 100644 --- a/src/main/java/GaussianElimintation/GaussianElimintation.java +++ b/src/main/java/GaussianElimintation/GaussianElimintation.java @@ -1,7 +1,7 @@ package GaussianElimintation; public class GaussianElimintation { - private double matrix[][]; + private Matrix matrix; private double result[]; private int N; @@ -9,67 +9,79 @@ public GaussianElimintation(double[][] matrix) { setMatrix(matrix); } + public GaussianElimintation(Double[][] matrix) { + setMatrix(matrix); + } + + public GaussianElimintation(Matrix matrix) { + setMatrix(matrix); + } + private double[] findAnswer() { double coefficient; result = new double[N--]; for (int counter = 0; counter < N; counter++) { for (int next = counter + 1; next <= N; next++) { - coefficient = matrix[next][counter] / matrix[counter][counter] * -1; - add(coefficient, matrix[counter], matrix[next], counter); + coefficient = matrix.getElement(next, counter) / matrix.getElement(counter, counter) * -1; + matrix.addRow(coefficient, counter, next, counter); } } for (int counter = N; counter >= 0; counter--) { - result[counter] = (matrix[counter][N + 1] - calculate(counter)) / matrix[counter][counter]; + result[counter] = (matrix.getElement(counter, N + 1) - calculate(counter)) / matrix.getElement(counter, counter); } return result; } - private double[] add(double[] what, double[] to, int skipFirst) { - return add(1, what, to, skipFirst); - } - - private double[] add(double[] what, double[] to) { - return add(1, what, to, 0); - } - - private double[] add(double coefficient, double[] what, double[] to, int skipFirst) { - for (int counter = skipFirst; counter <= N + 1; counter++) { - to[counter] += what[counter] * coefficient; - } - return to; - } - - public static boolean isSquareMatrix(double[][] matrix) { + /** + * Проверяет является ли матрица квадратной. Вектор значение после знака равенства не учитывается. + * + * @param matrix Матрица для проверки, включая столбец значений после знака раменства. + * @return true - матрица квадратная, false - нет + */ + public static boolean isSquareMatrix(Matrix matrix) { boolean result = true; - int N = matrix.length; - for (double[] line : matrix) { - result &= line.length == N + 1; + int N = matrix.getN(); + for (Row row : matrix.getRows()) { + result &= row.getDoubleList().size() == N + 1; } return result; } + /** + * Вычисление известной части уравнения + * @param stage индекс после которого происходит расчёт + * @return сумма известных частей полинома + */ private double calculate(int stage) { double result = 0.0; if (stage != N) { for (int counter = stage + 1; counter <= N; counter++) { - result += matrix[stage][counter] * this.result[counter]; + result += matrix.getElement(stage, counter) * this.result[counter]; } } return result; } public void setMatrix(double[][] matrix) { + setMatrix(new Matrix(matrix)); + } + + public void setMatrix(Double[][] matrix) { + setMatrix(new Matrix(matrix)); + } + + public void setMatrix(Matrix matrix) { try { if (!isSquareMatrix(matrix)) throw new RuntimeException("This matrix is not square matrix."); } catch (RuntimeException re) { re.printStackTrace(); } this.matrix = matrix; - N = this.matrix.length; + N = this.matrix.getN(); result = null; } - public double[][] getMatrix() { + public Matrix getMatrix() { return matrix; } diff --git a/src/main/java/GaussianElimintation/Matrix.java b/src/main/java/GaussianElimintation/Matrix.java index 4aab135..9d44bbb 100644 --- a/src/main/java/GaussianElimintation/Matrix.java +++ b/src/main/java/GaussianElimintation/Matrix.java @@ -2,25 +2,80 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; public class Matrix { - protected List rows; + private List rows; + private int N; + //TODO: Столбцы ? + + public Matrix(double[][] matrix) { + rows = new ArrayList(); + for (double[] row : matrix) { + rows.add(new Row(row)); + } + N = rows.size(); + } + + public Matrix(Double[][] matrix) { + rows = new ArrayList(); + for (Double[] row : matrix) { + rows.add(new Row(row)); + } + N = rows.size(); + } public Matrix(Row... rows) { this.rows = new ArrayList(Arrays.asList(rows)); + N = this.rows.size(); + } + + public Matrix(LinearEquation... linearEquations) { + rows = new ArrayList(); + for (LinearEquation linearEquation : linearEquations) { + rows.add(new Row(linearEquation)); + } + N = rows.size(); + } + + public Matrix addRow(int whatIndex, int toIndex) { + return addRow(1, whatIndex, toIndex, 0); + } + + public Matrix addRow(int whatIndex, int toIndex, int skipFirst) { + return addRow(1, whatIndex, toIndex, skipFirst); } - public Matrix(Collection rows) { - this.rows = new ArrayList(rows); + public Matrix addRow(double coefficient, int whatIndex, int toIndex, int skipFirst) { + return addRow(coefficient, rows.get(whatIndex), rows.get(toIndex), skipFirst); } + public Matrix addRow(Row what, Row to, int skipFirst) { + return addRow(1, what, to, skipFirst); + } + + public Matrix addRow(Row what, Row to) { + return addRow(1, what, to, 0); + } + + public Matrix addRow(double coefficient, Row what, Row to, int skipFirst) { + to.add(what, coefficient, skipFirst); + return this; + } public List getRows() { return rows; } + public Double getElement(int rowIndex, int columnIndex) { + return rows.get(rowIndex).getDouble(columnIndex); + } + + public int getN() { + return N; + } + public void setRows(List rows) { this.rows = rows; + N = this.rows.size(); } } diff --git a/src/main/java/GaussianElimintation/Row.java b/src/main/java/GaussianElimintation/Row.java index bfb2771..fe2834c 100644 --- a/src/main/java/GaussianElimintation/Row.java +++ b/src/main/java/GaussianElimintation/Row.java @@ -5,8 +5,14 @@ import java.util.List; public class Row { - protected List doubleList; + private List doubleList; + public Row(double... array) { + doubleList = new ArrayList(); + for (double one : array) { + doubleList.add(one); + } + } public Row(Double... array) { doubleList = new ArrayList<>(Arrays.asList(array)); } @@ -25,14 +31,20 @@ public void add(Row row, double coefficient) { } public void add(Row row, double coefficient, int skipFirst) { - Double[] to = (Double[]) doubleList.toArray(), - what = (Double[]) row.doubleList.toArray(); + Double[] to = new Double[doubleList.size()], + what = new Double[row.doubleList.size()]; + to = doubleList.toArray(to); + what = row.doubleList.toArray(what); for (int counter = skipFirst; counter < doubleList.size(); counter++) { to[counter] += what[counter] * coefficient; } doubleList = new ArrayList<>(Arrays.asList(to)); } + public Double getDouble(int index) { + return doubleList.get(index); + } + public LinearEquation toLinearEquation() { return new LinearEquation((Double[]) doubleList.toArray()); } From 797d5977b05ffa32561e57f404bc4e020510411f Mon Sep 17 00:00:00 2001 From: Anton Klimov Date: Sun, 16 Dec 2018 03:44:20 +0700 Subject: [PATCH 03/10] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20Mai?= =?UTF-8?q?n,=20=D0=BF=D1=80=D0=B8=D0=BD=D0=B8=D0=BC=D0=B0=D1=8E=D1=89?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=B2=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D1=85=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D1=81=20?= =?UTF-8?q?=D0=B2=D1=85=D0=BE=D0=B4=D0=BD=D1=8B=D0=BC=D0=B8=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=BC=D0=B8=20=D0=B8=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B8=20=D1=80=D0=B5=D0=B7=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D0=B0=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- in.txt | 4 ++ out.txt | 1 + .../GaussianElimintation.java | 2 +- src/main/java/GaussianElimintation/Main.java | 42 +++++++++++++++++++ src/main/java/SystemWith2Variables.java | 24 ----------- 5 files changed, 48 insertions(+), 25 deletions(-) create mode 100644 in.txt create mode 100644 out.txt delete mode 100644 src/main/java/SystemWith2Variables.java diff --git a/in.txt b/in.txt new file mode 100644 index 0000000..b0bf574 --- /dev/null +++ b/in.txt @@ -0,0 +1,4 @@ +3 +1 1 2 9 +2 4 -3 1 +3 6 -5 0 \ No newline at end of file diff --git a/out.txt b/out.txt new file mode 100644 index 0000000..621678b --- /dev/null +++ b/out.txt @@ -0,0 +1 @@ +1.0 2.0 3.0 \ No newline at end of file diff --git a/src/main/java/GaussianElimintation/GaussianElimintation.java b/src/main/java/GaussianElimintation/GaussianElimintation.java index 8cfba3b..c1d35b9 100644 --- a/src/main/java/GaussianElimintation/GaussianElimintation.java +++ b/src/main/java/GaussianElimintation/GaussianElimintation.java @@ -17,7 +17,7 @@ public GaussianElimintation(Matrix matrix) { setMatrix(matrix); } - private double[] findAnswer() { + public double[] findAnswer() { double coefficient; result = new double[N--]; for (int counter = 0; counter < N; counter++) { diff --git a/src/main/java/GaussianElimintation/Main.java b/src/main/java/GaussianElimintation/Main.java index ee6a7c6..800a5ff 100644 --- a/src/main/java/GaussianElimintation/Main.java +++ b/src/main/java/GaussianElimintation/Main.java @@ -1,7 +1,49 @@ package GaussianElimintation; +import java.io.*; + public class Main { public static void main(String[] args) { + BufferedReader in = null; + BufferedWriter out = null; + double[][] matrix; + double[] result; + String[] buffer; + int N; + GaussianElimintation gaussianElimintation; + + try { + for (int counter = 0; counter < 4; counter++) { + if (args[counter].equals("-in")) { + in = new BufferedReader(new FileReader(args[++counter])); + } + if (args[counter].equals("-out")) { + out = new BufferedWriter(new FileWriter(args[++counter])); + } + } + + if (in == null || out == null) return; + + buffer = in.readLine().split(" "); + N = Integer.parseInt(buffer[0]); + matrix = new double[N][]; + for (int row = 0; row < N; row++) { + matrix[row] = new double[N + 1]; + buffer = in.readLine().split(" "); + for (int column = 0; column <= N; column++) { + matrix[row][column] = Double.parseDouble(buffer[column]); + } + } + in.close(); + gaussianElimintation = new GaussianElimintation(matrix); + result = gaussianElimintation.findAnswer(); + for (int counter = 0; counter < N; counter++) { + out.append(Double.toString(result[counter]) + " "); + } + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } diff --git a/src/main/java/SystemWith2Variables.java b/src/main/java/SystemWith2Variables.java deleted file mode 100644 index e19974e..0000000 --- a/src/main/java/SystemWith2Variables.java +++ /dev/null @@ -1,24 +0,0 @@ -import java.util.Scanner; - -public class SystemWith2Variables { - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - double a, - b, - c, - d, - f, - e, - y, - x; - a = sc.nextDouble(); - b = sc.nextDouble(); - c = sc.nextDouble(); - d = sc.nextDouble(); - e = sc.nextDouble(); - f = sc.nextDouble(); - y = (f - c * d / a) / (e - b * d / a); - x = (c - b * y) / a; - System.out.println(x + " " + y); - } -} From 7b6458afe4e6589873e3616b9c8688e8cb3e3bbc Mon Sep 17 00:00:00 2001 From: Anton Klimov Date: Sun, 16 Dec 2018 03:58:20 +0700 Subject: [PATCH 04/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D1=8F=D1=81=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BA=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/GaussianElimintation/GaussianElimintation.java | 4 ++++ src/main/java/GaussianElimintation/LinearEquation.java | 6 +++++- src/main/java/GaussianElimintation/Main.java | 6 ++++++ src/main/java/GaussianElimintation/Matrix.java | 6 +++++- src/main/java/GaussianElimintation/Row.java | 5 +++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/GaussianElimintation/GaussianElimintation.java b/src/main/java/GaussianElimintation/GaussianElimintation.java index c1d35b9..64ed364 100644 --- a/src/main/java/GaussianElimintation/GaussianElimintation.java +++ b/src/main/java/GaussianElimintation/GaussianElimintation.java @@ -1,5 +1,9 @@ package GaussianElimintation; +/** + * Класс для нахлждения вектора решений системы уравнений методом Гаусса + */ + public class GaussianElimintation { private Matrix matrix; private double result[]; diff --git a/src/main/java/GaussianElimintation/LinearEquation.java b/src/main/java/GaussianElimintation/LinearEquation.java index 538006b..9b83cb0 100644 --- a/src/main/java/GaussianElimintation/LinearEquation.java +++ b/src/main/java/GaussianElimintation/LinearEquation.java @@ -4,7 +4,11 @@ import java.util.Arrays; import java.util.List; -public class LinearEquation { +/** + * Класс линейного уравнения + */ + +public abstract class LinearEquation { protected List coefficients = new ArrayList(); protected Double rightSide; diff --git a/src/main/java/GaussianElimintation/Main.java b/src/main/java/GaussianElimintation/Main.java index 800a5ff..cd7cb34 100644 --- a/src/main/java/GaussianElimintation/Main.java +++ b/src/main/java/GaussianElimintation/Main.java @@ -2,6 +2,11 @@ import java.io.*; +/** + * Обязательные аргументы запуска это флаги "-in" и "-out", после которых следует имя файла с исходными данными или + * имя файла для вывода значения сооттветственно. + */ + public class Main { public static void main(String[] args) { BufferedReader in = null; @@ -42,6 +47,7 @@ public static void main(String[] args) { out.append(Double.toString(result[counter]) + " "); } out.close(); + System.out.println("Completed!"); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/GaussianElimintation/Matrix.java b/src/main/java/GaussianElimintation/Matrix.java index 9d44bbb..4d50c24 100644 --- a/src/main/java/GaussianElimintation/Matrix.java +++ b/src/main/java/GaussianElimintation/Matrix.java @@ -4,10 +4,13 @@ import java.util.Arrays; import java.util.List; +/** + * Класс матрицы, поддерживающий только элементарные преобразования умножения и складывания только со строками матрицы. + */ + public class Matrix { private List rows; private int N; - //TODO: Столбцы ? public Matrix(double[][] matrix) { rows = new ArrayList(); @@ -62,6 +65,7 @@ public Matrix addRow(double coefficient, Row what, Row to, int skipFirst) { to.add(what, coefficient, skipFirst); return this; } + public List getRows() { return rows; } diff --git a/src/main/java/GaussianElimintation/Row.java b/src/main/java/GaussianElimintation/Row.java index fe2834c..3616243 100644 --- a/src/main/java/GaussianElimintation/Row.java +++ b/src/main/java/GaussianElimintation/Row.java @@ -4,6 +4,10 @@ import java.util.Arrays; import java.util.List; +/** + * Класс строки матрицы или же представление линейного уравнения через вектор коэффициентов + */ + public class Row { private List doubleList; @@ -13,6 +17,7 @@ public Row(double... array) { doubleList.add(one); } } + public Row(Double... array) { doubleList = new ArrayList<>(Arrays.asList(array)); } From 8427d7d57f05dc74de324f9afe32f939646753a8 Mon Sep 17 00:00:00 2001 From: Anton Klimov Date: Sun, 16 Dec 2018 04:14:09 +0700 Subject: [PATCH 05/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..04ba0c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,109 @@ + +# Created by https://www.gitignore.io/api/java,intellij +# Edit at https://www.gitignore.io/?templates=java,intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# End of https://www.gitignore.io/api/java,intellij From 01210a2edf586bba9bc9b58883c9c90cce5301c1 Mon Sep 17 00:00:00 2001 From: Anton Klimov Date: Sun, 16 Dec 2018 04:17:08 +0700 Subject: [PATCH 06/10] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 04ba0c9..8b2e2dc 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,9 @@ fabric.properties # .idea/misc.xml # *.ipr +# IntelliJ IDEA folder +.idea/ + # Sonarlint plugin .idea/sonarlint From 3344170fb33de86a2073453db76bf745cd17b7aa Mon Sep 17 00:00:00 2001 From: Anton Klimov Date: Sun, 16 Dec 2018 04:18:52 +0700 Subject: [PATCH 07/10] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20.gitignore=20=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 8b2e2dc..be8b6d5 100644 --- a/.gitignore +++ b/.gitignore @@ -81,6 +81,9 @@ fabric.properties # IntelliJ IDEA folder .idea/ +#module +rujnster.iml + # Sonarlint plugin .idea/sonarlint From 2afc654cd57ffef8a14be56fb47d7b400bece40c Mon Sep 17 00:00:00 2001 From: Jnster Date: Sun, 16 Dec 2018 04:20:16 +0700 Subject: [PATCH 08/10] Delete misc.xml --- .idea/misc.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index a165cb3..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 69924b2ba8dfa3a2d0244e2fb896e3413f3cd60e Mon Sep 17 00:00:00 2001 From: Jnster Date: Sun, 16 Dec 2018 04:20:32 +0700 Subject: [PATCH 09/10] Delete modules.xml --- .idea/modules.xml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .idea/modules.xml diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index a0733a5..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file From 1bee331b085ecfea6a7af0e9719010f1626939b0 Mon Sep 17 00:00:00 2001 From: Jnster Date: Sun, 16 Dec 2018 04:20:44 +0700 Subject: [PATCH 10/10] Delete project.iml --- .idea/project.iml | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 .idea/project.iml diff --git a/.idea/project.iml b/.idea/project.iml deleted file mode 100644 index 47baa8c..0000000 --- a/.idea/project.iml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file