#pragma once
#include <cmath>
class Matrix {
public:
Matrix() : x11(0.0), x12(0.0), x21(0.0), x22(0.0) {}
Matrix(double x11, double x12, double x21, double x22)
: x11(x11), x12(x12), x21(x21), x22(x22) {}
public:
double determinant() {
return x11 * x22 - x12 * x21;
}
Matrix inverse() {
double determinant = this->determinant();
if (determinant == 0) {
return Matrix();
}
double x11 = (pow(-1, 2) * this->x22) / determinant;
double x12 = (pow(-1, 3) * this->x12) / determinant;
double x21 = (pow(-1, 3) * this->x21) / determinant;
double x22 = (pow(-1, 4) * this->x11) / determinant;
return Matrix(x11, x12, x21, x22);
}
public:
Matrix operator=(Matrix mat) {
return Matrix(mat);
}
private:
double x11, x12, x21, x22;
};
Comments
Leave a comment