public static Matrix2 operator *(Matrix2 first, Matrix2 second) { Matrix2 result = new Matrix2() { A11 = first.A11 * second.A11 + first.A12 * second.A21, A12 = first.A11 * second.A12 + first.A12 * second.A22, A21 = first.A21 * second.A11 + first.A22 * second.A21, A22 = first.A21 * second.A12 + first.A22 * second.A22 }; return(result); }
public Matrix2(Matrix2 matrix1) { matrix = new double[2][]; matrix[0] = new double[2]; matrix[1] = new double[2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { this.matrix[i][j] = matrix1.matrix[i][j]; } } }
public static Matrix2 operator -(Matrix2 mat1, Matrix2 mat2) { Matrix2 mat = new Matrix2(0, 0); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { mat.matrix[i][j] = mat1.matrix[i][j] - mat2.matrix[i][j]; } } return(mat); }
public static Matrix2 operator /(Matrix2 mat1, double value) { Matrix2 mat = new Matrix2(mat1); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { mat.matrix[i][j] /= value; } } return(mat); }
public Matrix2 Inverse() { double det = Det(); Matrix2 mat = new Matrix2(0, 0); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { mat.matrix[i][j] = Math.Pow(-1, (i + j)) * matrix[1 - i][1 - j] / det; } } return(mat.Transpose()); }
public static Matrix2 operator *(Matrix2 mat1, Matrix2 mat2) { Matrix2 mat = new Matrix2(0, 0); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { double sum = 0; for (int l = 0; l < 2; l++) { sum += mat1.matrix[i][l] * mat2.matrix[l][j]; } mat.matrix[i][j] = sum; } } return(mat); }
public static Matrix2 Transpose(Matrix2 matrix2) { return(new Matrix2(matrix2.A11, matrix2.A21, matrix2.A12, matrix2.A22)); }
public static Matrix2 Inverse(Matrix2 matrix2) { return(Transpose(new Matrix2(matrix2.A22, -matrix2.A21, -matrix2.A12, matrix2.A11)) / Det(matrix2)); }
public static double Det(Matrix2 matrix2) { return(matrix2.A11 * matrix2.A22 - matrix2.A12 * matrix2.A21); }