# package ru kpfu itis group11402 batyrova Task055 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``` ```package ru.kpfu.itis.group11402.batyrova.Task055; import ru.kpfu.itis.group11402.batyrova.Task050.RationalFraction; import ru.kpfu.itis.group11402.batyrova.Task053.RationalVector2D; /** * @author Elvira Batyrova * 402 * 055 */ public class RationalMatrix2x2 { private RationalFraction[][]matrix = new RationalFraction[2][2]; public RationalFraction[][] getMatrix() { return matrix; } public void setMatrix(RationalFraction[][] matrix) { this.matrix = matrix; } public RationalMatrix2x2() { this(new RationalFraction[][] {{new RationalFraction(),new RationalFraction()},{new RationalFraction(),new RationalFraction()}}); } public RationalMatrix2x2(RationalFraction r) { this(new RationalFraction[][] {{r,r},{r,r}}); } public RationalMatrix2x2(RationalFraction[][] matrix) { this.matrix = matrix; } public RationalMatrix2x2(RationalFraction a1, RationalFraction a2, RationalFraction a3, RationalFraction a4) { this(new RationalFraction[][] {{a1,a2},{a3,a4}}); } public RationalMatrix2x2 add(RationalMatrix2x2 rmatr) { RationalMatrix2x2 result = new RationalMatrix2x2(); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { result.matrix[i][j] = this.matrix[i][j].add(rmatr.getMatrix()[i][j]); } } return result; } public RationalMatrix2x2 mult(RationalMatrix2x2 rmatr) { RationalMatrix2x2 result = new RationalMatrix2x2(); 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].mult(rmatr.getMatrix()[k][j]); } } } return result; } public RationalFraction det() { return matrix[0][0].mult(matrix[1][1]).sub(matrix[0][1].mult(matrix[1][0])); } ```