package ru kpfu itis group11402 batyrova Task059 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
package ru.kpfu.itis.group11402.batyrova.Task059;
import ru.kpfu.itis.group11402.batyrova.Task057.RationalComplexNumber;
import ru.kpfu.itis.group11402.batyrova.Task058.RationalComplexVector2D;
/**
* @author Elvira Batyrova
* 402
* 059
*/
public class RationalComplexMatrix2x2 {
private RationalComplexNumber[][]matrix = new RationalComplexNumber[2][2];
public RationalComplexNumber[][] getMatrix() {
return matrix;
}
public void setMatrix(RationalComplexNumber[][] matrix) {
this.matrix = matrix;
}
public RationalComplexMatrix2x2() {
this(new RationalComplexNumber[][] {{new RationalComplexNumber(),new RationalComplexNumber()},{new RationalComplexNumber(),new RationalComplexNumber()}});
}
public RationalComplexMatrix2x2(RationalComplexNumber a) {
this(new RationalComplexNumber[][] {{a,a},{a,a}});
}
public RationalComplexMatrix2x2(RationalComplexNumber[][] matrix) {
this.matrix = matrix;
}
public RationalComplexMatrix2x2(RationalComplexNumber a1, RationalComplexNumber a2, RationalComplexNumber a3, RationalComplexNumber a4) {
this(new RationalComplexNumber[][] {{a1,a2},{a3,a4}});
}
public RationalComplexMatrix2x2 add(RationalComplexMatrix2x2 rcm) {
RationalComplexMatrix2x2 result = new RationalComplexMatrix2x2();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
result.matrix[i][j] = this.matrix[i][j].add(rcm.getMatrix()[i][j]);
}
}
return result;
}
public RationalComplexMatrix2x2 mult(RationalComplexMatrix2x2 rcm) {
RationalComplexMatrix2x2 result = new RationalComplexMatrix2x2();
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].add(this.matrix[i][k].mult(rcm.getMatrix()[k][j]));
}
}
}
return result;
}
public RationalComplexNumber det() {
return matrix[0][0].mult(matrix[1][1]).sub(matrix[0][1].mult(matrix[1][0]));
}
public RationalComplexVector2D multVector(RationalComplexVector2D rcv) {
return new RationalComplexVector2D(this.matrix[0][0].mult(rcv.getX()).add(this.matrix[0][1].mult(rcv.getY())),
this.matrix[1][0].mult(rcv.getX()).add(this.matrix[1][1].mult(rcv.getY())));
}
public String toString() {
return (matrix[0][0].toString() + " " + matrix[0][1].toString() + "\n" + matrix[1][0].toString() + " " + matrix[1][1].toString() + "\n");
}
}