Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.omsu.imit.kr.Matrix;
- import com.sun.javafx.geom.transform.SingularMatrixException;
- import java.util.Arrays;
- /**
- * Created by User on 15.02.2017.
- */
- public class Matrix implements IMatrix {
- private int n; // размер
- private double matr[]; // сам массив
- public Matrix(int n) throws SingularMatrixException { // конструктор по размеру
- if (n < 0) {
- throw new SingularMatrixException();
- }
- this.n = n;
- matr = new double[n * n];
- }
- public Matrix(double[] arr) throws SingularMatrixException { //конструктор копирования
- if(Math.sqrt(arr.length) % 1 == 0){
- n = new Double(Math.sqrt(arr.length)).intValue();
- System.arraycopy(arr,0,matr, 0,arr.length);
- }
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Matrix matrix = (Matrix) o;
- if (n != matrix.n) return false;
- return Arrays.equals(matr, matrix.matr);
- }
- @Override
- public int getLength() {
- return matr.length;
- }
- @Override
- public int hashCode() {
- int result = n;
- result = 31 * result + Arrays.hashCode(matr);
- return result;
- }
- @Override
- public double getElem(int i, int j) {
- return matr[n * i + j];
- }
- public void setN(int n) {
- this.n = n;
- }
- @Override
- public void setElem(int i, int j, double elem) throws SingularMatrixException {
- if ((i < 0) || (i > n) || (j < 0) || (j > n)) {
- throw new SingularMatrixException();
- }
- this.matr[n * i + j] = elem;
- }
- public double getDeg() {
- double deg = 1;
- Matrix resmatr = new Matrix(matr);
- //копия матрицы
- for (int k = 0; k < matr.length; k++) { //кол-во зануленных столбцов
- //проверка на 0
- for (int i = k + 1; i < matr.length; i++) { //по строке
- for (int j = k; j < matr.length; j++) { // по столбцу
- double res = resmatr.getElem(i, j) - ((resmatr.getElem(i, k) * resmatr.getElem(k, j)) / resmatr.getElem(k, k));
- resmatr.setElem(i, j, res);
- }
- }
- }
- for (int x = 0; x < matr.length; x++) {
- deg = deg * resmatr.getElem(x, x); // элементики по диагонали
- }
- return deg;
- }
- /* функция умножения строки на модуль
- public double[] Coef(int x, int y, double[]str, double[]str1) {
- double elem1=x/y;
- return
- }
- @Override
- public double getDeg() {
- double deg;
- for (int i = 0; i < (matr.length-1); i++){
- }
- return deg;
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement