le_gaussseideliteration.cpp

来自「计算机常用数值算法与程序(C++版) Chap07 线性方程组求解」· C++ 代码 · 共 40 行

CPP
40
字号
//LE_GaussSeidelIteration.cpp	高斯-赛德尔迭代法 

#include <iostream>				//输入输出流头文件
#include "LinearEquation.h"		//线性方程(组)求解头文件

void main()
{ 
	int i;
    double eps;
    
	double a[4][4] = 
	{
		{7.0,  2.0,  1.0,  -2.0},
		{9.0,  15.0, 3.0,  -2.0},
		{-2.0, -2.0, 11.0,  5.0},
		{1.0,  3.0,  2.0,  13.0}
	};
    
	double b[4] = {4.0, 7.0, -1.0, 0.0};

   	valarray<double> xx(5);
	valarray<double> bb(b, 4);
	matrix<double> aa(&a[0][0], 4, 4);
	
	eps = FLOATERROR;
	
  	cout.setf(ios::fixed);	//输出数据为定点法
	cout.precision(6);		//精度6位
    
	if(LE_GaussSeidelIteration(aa, bb, xx, eps) > 0)
	{
		for(i = 0; i < 4; i ++)
        {
			cout << "x(" << i << ") = " << xx[i] << endl;
		}
	}
	cout << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?