数值分析–4–高斯消元法(2)
/**
+———————————————————-
* 计算矩阵—普通算法
+———————————————————-
* @access public
+———————————————————-
* @return void
+———————————————————-
*/
void cout_n() {
double x_muti;
//下列减法
double down_total=0;
//上列加法
double up_total=0;
int r;
int s;
//下列算法
for (int j = 0; j < this->cols; j++) {
x_muti=1;
r=j;
//遍历行
for (int i = 0; i < this->rows; i++) {
if(++r<=this->cols){
s=r;
}
else{
s=r–this->cols;
}
//cout<<"i:"<<i<<"s:"<<s<<endl;
// 对角相乘
x_muti=x_muti*this->DIAGRAM[i][s–1];
}
down_total += x_muti;
}
int d;
//上列算法
for (int j = 0; j < this->cols; j++) {
x_muti=1;
r=j–1;
//遍历行
d=this->rows–1;
for (int i = 0; i < this->rows; i++) {
if(++r<this->cols){
s=r;
}
else{
s=r–this->cols;
}
//cout<<"s:"<<s<<"d:"<<d<<endl;
// 对角相乘
x_muti=x_muti*this->DIAGRAM[d–][s];
}
up_total += x_muti;
}
cout<<up_total–down_total<<endl;
}
/**
+———————————————————-
* 计算矩阵—高斯消元法
+———————————————————-
* @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++)
{
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;
cout<<"xn:"<<(double)this->DIAGRAM[g][s]<<endl;
}
this->print_g();
}
}
}
};
}
#endif