Big Bug Ban

兴趣 践行 创新

计算矩阵–高斯消元法 接上..

 

        /**
+———————————————————-
* 计算矩阵–高斯列主元消元法
+———————————————————-
* @access public
+———————————————————-
* @return void
+———————————————————-
*/

void cout_z(){

for(int j = 0; j < this->cols; j++){

int r=j+1;

for(int g=r;g<this->rows;g++)
{
//列主元
if(g==r)
{for(int z=r-1;z<this->rows;z++)
{
if(DIAGRAM[r-1][g-1]<DIAGRAM[r][g-1])
{
cout<<"A is "<<DIAGRAM[r-1][g-1]<<endl;
cout<<"B is "<<DIAGRAM[r][g-1]<<endl;
this->h(r,r+1);
cout<<"change"<<r-1<<"with"<<r<<"rows"<<endl;
this->print_g();
}
}
}
//求xn
double xn=this->DIAGRAM[g][j]/this->DIAGRAM[j][j];

cout<<"xn:"<<xn<<endl;

for(int s = 0; s < this->cols; s++){

this->DIAGRAM[g][s]=this->DIAGRAM[j][s]-this->DIAGRAM[g][s]/xn;
//消除小差差
if(this->DIAGRAM[g][s]<devia && this->DIAGRAM[g][s]>-devia)
{
this->DIAGRAM[g][s]=0;
}
//cout<<"xn:"<<(double)this->DIAGRAM[g][s]<<endl;
}
this->print_g();
}

}

}

上次那个文件里面行列交换写反了…

Written by princehaku

10月 21st, 2009 at 9:30 上午

Posted in c/c++

without comments

Leave a Reply