include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class matrix {
private:
double a11, a12, a21, a22;
public:
void inverse() {
double det = a11 * a22 - a12 * a21;
if (fabs(det) < 1e-9) {
cout << "singular matrix" << endl;
} else {
double invDet = 1.0 / det;
cout << fixed << setprecision(1)
<< a22 * invDet << " " << -a12 * invDet << endl
<< -a21 * invDet << " " << a11 * invDet << endl;
}
}
friend istream& operator>>(istream& is, matrix& m) {
is >> m.a11 >> m.a12 >> m.a21 >> m.a22;
return is;
}
friend ostream& operator<<(ostream& os, const matrix& m) {
os << m.a11 << " " << m.a12 << " " << m.a21 << " " << m.a22;
return os;
}
};
int main() {
matrix A;
cin >> A;
A.inverse();
return 0;
}
反矩陣計算 (Matrix Inversion)
最新推荐文章于 2024-10-17 21:05:59 发布