package ru kpfu itis group11402 batyrova Task052 import ru kpfu itis g

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package ru.kpfu.itis.group11402.batyrova.Task052;
import ru.kpfu.itis.group11402.batyrova.Task049.Vector2D;
/**
* Created by DNS on 19.11.2014.
*/
public class Matrix2x2 {
private double[][]matrix = new double[2][2];
public double[][] getMatrix() {
return matrix;
}
public void setMatrix(double[][] matrix) {
this.matrix = matrix;
}
public Matrix2x2() {
this(new double[][]{{0,0},{0,0}});
}
public Matrix2x2(double c) {
this(new double[][]{{c,c},{c,c}});
}
public Matrix2x2(double[][] matrix) {
this.matrix = matrix;
}
public Matrix2x2(double b1, double b2, double b3, double b4) {
this(new double[][]{{b1,b2},{b3,b4}});
}
public Matrix2x2 add(Matrix2x2 matr) {
Matrix2x2 result = new Matrix2x2();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
result.matrix[i][j] = this.matrix[i][j] + matr.getMatrix()[i][j];
}
}
return result;
}
public void add2(Matrix2x2 matr) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
this.matrix[i][j] += matr.getMatrix()[i][j];
}
}
}
public Matrix2x2 sub(Matrix2x2 matr) {
Matrix2x2 result = new Matrix2x2();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
result.matrix[i][j] = this.matrix[i][j] - matr.getMatrix()[i][j];
}
}
return result;
}
public void sub2(Matrix2x2 matr) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
this.matrix[i][j] -= matr.getMatrix()[i][j];
}
}
}
public Matrix2x2 multNumber(double v) {
Matrix2x2 result = new Matrix2x2();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
result.matrix[i][j] = this.matrix[i][j] * v;
}
}
return result;
}
public void multNumber2(double v) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
this.matrix[i][j] *= v;
}
}
}
public Matrix2x2 mult(Matrix2x2 matr) {
Matrix2x2 result = new Matrix2x2();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
result.matrix[i][j] += this.matrix[i][k] * matr.getMatrix()[k][j];
}
}
}
return result;
}
public void mult2(Matrix2x2 matr) {
this.matrix = this.mult(matr).getMatrix();
}
public double det() {
return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
}
public void transpon() {
double c = matrix[0][1];
matrix[0][1] = matrix[1][0];
matrix[1][0] = c;
}
public Matrix2x2 inverseMatrix() {
if (this.det() == 0) {
System.out.println("Обратной матрицы не существует");
return new Matrix2x2();
} else {
Matrix2x2 mt = new Matrix2x2();
mt.matrix[0][0] = this.matrix[1][1] / this.det();
mt.matrix[1][1] = this.matrix[0][0] / this.det();
mt.matrix[0][1] = - this.matrix[1][1] / this.det();
mt.matrix[1][0] = - this.matrix[1][1] / this.det();
return mt;
}
}
public Matrix2x2 equivalentDiagonal() {
Matrix2x2 mt = new Matrix2x2();
mt.matrix[0][0] = this.matrix[0][0] * this.matrix[1][1] - this.matrix[0][1] * this.matrix[0][0];
mt.matrix[1][1] = this.matrix[1][1];
mt.matrix[0][1] = 0;
mt.matrix[1][0] = 0;
return mt;
}
public Vector2D multVector(Vector2D vect) {
return new Vector2D (vect.getX() * matrix[0][0] + vect.getX() * matrix[0][1], vect.getY() * matrix[1][0] + vect.getY() * matrix[1][1]);
}
}