Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
InverseMatrix2n2
//g++ 7.4.0 //Inverse of a 2x2 square matrix // credit: John R. Hubbard ,University of Richmond #include <iostream> using namespace std; class Matrix { public: Matrix (double a=0, double b=0, double c=0, double d=0) : r11(a), r12(b),r21(c), r22(d) {} Matrix (const Matrix& s) : r11(s.r11),r12(s.r12),r21(s.r21),r22(s.r22) {} double det() { return (r11*r22 - r12*r21);} int isSingular() { return det() == 0;} Matrix inverse(); void print (); private: double r11,r12,r21,r22; }; Matrix Matrix :: inverse() { double k = 1/det(); Matrix temp (k*r22,-k*r12,-k*r21,k*r11); return temp; } void Matrix :: print() { cout<<r11<<" "<<r12<<'\n'<<r21<<" "<<r22<<'\n'; } int main() { Matrix m(1,2,3,4); cout<<"The matrix looks like:\n"; m.print(); cout<<endl; if(!m.isSingular()) cout<<"The matrix is nonsingular."<<endl; cout<<"After the inversion the matrix looks like:\n"; Matrix p; p=m.inverse(); p.print(); return 0; }
run
|
edit
|
history
|
help
0
GCC bug #79511
max_size()_30-Seconds-of-C++
MapTel2
HashConPar
horse aand goat working
an awesome question of basic graph traversal (786A)
w1
Boost phoenix. e.g 2: functor
thermal_containers
2015(M2)Mod.