class Matrix{
private :
double Val[10][10];
int Column,Row;
public :
double Val[10][10];
int Column,Row;
void show(){
puts("****");
cout<<"Row = "<<Row<<" Column = "<<Column<<endl;
puts("-----------------");
for(int i = 1 ; i <= Row ; i++){
for(int j = 1 ; j <= Column ; j++){
printf("%.3lf\t%c",Val[i][j],j==Column?'\n':' ');
}
}
puts("****");
}
void init(){
cout<<"gets row and column first"<<endl;
cin>>Row>>Column;
cout<<"gets values now"<<endl;
for(int i = 1 ; i <= Row ; i++){
for(int j = 1 ; j <= Column ; j++){
cin>>Val[i][j];
}
}
}
Matrix Transpose(){
Matrix ret;
ret.Column=Row;
ret.Row=Column;
for(int i=1 ; i<=Row ; i++){
for(int j=1 ; j<=Column ; j++){
ret.Val[j][i]=Val[i][j];
}
}
return ret;
}
Matrix Multiply(Matrix a){
Matrix ret;
ret.Row=Row;
ret.Column=a.Column;
for(int i=1 ; i<= ret.Row ; i++){
for(int j=1 ; j<= ret.Column ; j++){
double tmp=0;
for(int k=1 ; k<= Column ; k++){
tmp+=Val[i][k]*a.Val[k][j];
}
ret.Val[i][j]=tmp;
}
}
return ret;
}
double Absolute(){
double ret=0;
if(Row==2){
ret=Val[1][1]*Val[2][2]-Val[1][2]*Val[2][1];
return ret;
}
else{
Matrix tmp[Row+1][Row+1];
for(int i=1 ; i<= Row ; i++){
for(int j=1 ; j<= Column ; j++){
int pre;
if((i+j)%2==0)pre=1;
else pre=-1;
tmp[i][j].Row=Row-1;
tmp[i][j].Column=Column-1;
for(int ii=1,xi=1 ; ii <= Row ; ii++){
if(ii==i)continue;
for(int jj=1,xj=1 ; jj <= Column ; jj++){
if(jj==j)continue;
tmp[i][j].Val[xi][xj]=Val[ii][jj];
xj++;
}
xi++;
}
ret+=pre*Val[i][j]*tmp[i][j].Absolute();
}
}
return ret/Row;
}
}
Matrix Adjoint_matrix (){
Matrix ret;
Matrix tmp[Row+1][Row+1];
ret.Row=Row;
ret.Column=Column;
for(int i=1 ; i<= Row ; i++){
for(int j=1 ; j<= Column ; j++){
double values;
int pre;
if((i+j)%2==0)pre=1;
else pre=-1;
tmp[i][j].Row=Row-1;
tmp[i][j].Column=Column-1;
for(int ii=1,xi=1 ; ii <= Row ; ii++){
if(ii==i)continue;
for(int jj=1,xj=1 ; jj <= Column ; jj++){
if(jj==j)continue;
tmp[i][j].Val[xi][xj]=Val[ii][jj];
xj++;
}
xi++;
}
values=pre*tmp[i][j].Absolute();
ret.Val[i][j]=values;
}
}
return ret.Transpose();
}
Matrix Inverse (Matrix a){
Matrix ret=a.Adjoint_matrix();
double ab=a.Absolute();
for(int i=1 ; i<= Row ; i++){
for(int j=1 ; j<= Row ; j++){
ret.Val[i][j]/=ab;
}
}
return ret;
}
};