public class Matrix2x2 private double matrix new double public double

 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
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.matrix[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.matrix[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.matrix[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.matrix[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++) {
result.matrix[i][j] = 0;
for (int k = 0; k < 2; k++) {
result.matrix[i][j] += this.matrix[i][k] * matr.matrix[k][i];
}
}
}
return result;
}
}