#include <iostream> #include <vector> using namespace std; int main() { int i,j,m,times;//m represemt both row mumber and columm mumber cout<<"please input the row mumber/column number m:"; cin>>m; cout<<"please input the times of cycle times:"; cin>>times; vector<vector<double> > A(m,vector<double>(m)); vector<vector<double> > b(m,vector<double>(1)); vector<vector<double> > uni(m,vector<double>(m)); vector<vector<double> > Dni(m,vector<double>(m)); vector<vector<double> > multi(m,vector<double>(m)); vector<vector<double> > B(m,vector<double>(m)); vector<vector<double> > g(m,vector<double>(1)); vector<vector<double> > x0(m,vector<double>(1)); vector<vector<double> > x1(m,vector<double>(1)); for(i=0;i<m;++i) for(j=0;j<m;++j) { double temp; cout<<"please input the mumber in array["<<i<<","<<j<<"] :"; cin>>temp; A[i][j]=temp; } for(i=0;i<m;++i) { double temp; cout<<"please input the mumber in b["<<i<<"] :"; cin>>temp; b[i][0]=temp; } for(i=0;i<m;++i) for(j=0;j<m;++j) { if(i==j) { uni[i][j]=1; Dni[i][j]=1/A[i][j]; } } for(i=0;i<m;++i) for(j=0;j<m;++j) { int k=0; while(k<m) { multi[i][j]+=Dni[i][k]*A[k][j]; k++; } } for(i=0;i<m;++i) for(j=0;j<m;++j) { B[i][j]=uni[i][j]-multi[i][j]; } for(i=0;i<m;++i) { int k=0; while(k<m) { g[i][0]+=Dni[i][k]*b[k][0]; k++; } } while(times!=0) { for(i=0;i<m;++i) { int k=0; while(k<m) { x1[i][0]+=B[i][k]*x0[k][0]; k++; } x1[i][0]+=g[i][0]; } if(times!=1) { for(i=0;i<m;++i) { x0[i][0]=x1[i][0]; x1[i][0]=0; } } times--; } // output the elements of array x cout<<endl; cout<<"x:"<<endl; for(i=0;i<m;++i) for(j=0;j<1;++j) { if(j==0) { cout<<x1[i][j]<<endl; } else cout<<x1[i][j]<<"/t"; } // output the elements of array A cout<<endl; cout<<"A:"<<endl; for(i=0;i<m;++i) for(j=0;j<m;++j) { if(j==m-1) { cout<<A[i][j]<<endl; } else cout<<A[i][j]<<"/t"; } // output the elements of array uni cout<<endl; cout<<"uni:"<<endl; for(i=0;i<m;++i) for(j=0;j<m;++j) { if(j==m-1) { cout<<uni[i][j]<<endl; } else cout<<uni[i][j]<<"/t"; } // output the elements of array Dni cout<<endl; cout<<"Dni:"<<endl; for(i=0;i<m;++i) for(j=0;j<m;++j) { if(j==m-1) { cout<<Dni[i][j]<<endl; } else cout<<Dni[i][j]<<"/t"; } // output the elements of array multi cout<<endl; cout<<"multi:"<<endl; for(i=0;i<m;++i) for(j=0;j<m;++j) { if(j==m-1) { cout<<multi[i][j]<<endl; } else cout<<multi[i][j]<<"/t"; } // output the elements of array B cout<<endl; cout<<"B:"<<endl; for(i=0;i<m;++i) for(j=0;j<m;++j) { if(j==m-1) { cout<<B[i][j]<<endl; } else cout<<B[i][j]<<"/t"; } // output the elements of array g cout<<endl; cout<<"g:"<<endl; for(i=0;i<m;++i) for(j=0;j<1;++j) { if(j==0) { cout<<g[i][j]<<endl; } else cout<<g[i][j]<<"/t"; } // output the elements of array b cout<<endl; cout<<"b:"<<endl; for(i=0;i<m;++i) for(j=0;j<1;++j) { if(j==0) { cout<<b[i][j]<<endl; } else cout<<b[i][j]<<"/t"; } return 0; }