⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 高斯-赛德尔迭代法.cpp

📁 数值分析(计算方法):欧拉方法、高斯-赛德尔迭代法、拉格朗日及分段线性插值、龙贝格算法、牛顿下山法、选主元高斯消去法
💻 CPP
字号:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int max(double x,double y,double z)
{double t;   
	if(x>=y) t=x;
	else t=y;
	if(t>=z) return t;
	else return z;
}

void main()
{double a[3][3],b[3],x[3]={0,0,0},y[3]={0,0,0},c[3],e,sum;
int n,i,j,k;
cout<<"input a[3][3]:"<<endl;
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
cin>>a[i][j];
}
cout<<"input b[3]:"<<endl;
for(i=0;i<3;i++)
cin>>b[i];
cout<<"input e:"<<endl;
cin>>e;
cout<<"intput n:"<<endl;
cin>>n;

for(k=1;k<=n;k++)
{
	for(i=0;i<3;i++)
{sum=0;
	for(j=0;j<3;j++) 
	{	if(j!=i)
	 sum=sum+a[i][j]*y[j];
       else continue;	 
	}
	y[i]=(b[i]-sum)/a[i][i];
    c[i]=fabs(y[i]-x[i]);
	}
if(max(c[0],c[1],c[2])>=e)
{cout<<setprecision(8)<<showpoint<<y[0];
cout<<setprecision(8)<<showpoint<<' '<<y[1];
cout<<setprecision(8)<<showpoint<<' '<<y[2]<<endl;}   
else 
for(i=0;i<3;i++)
y[i]=x[i];
continue;
}
}

⌨️ 快捷键说明

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