雅克比迭代法…… 下载本文

内容发布更新时间 : 2024/5/20 3:49:13星期一 下面是文章的全部内容请认真阅读。

③ 超松弛因子迭代法 #in elude

#in elude using n amespaee std; float *on e_array_malloc(i nt n); float **two_array_malloc(i nt m,i nt n); float matrix_category(float* x,i nt n); int mai n(){ con st i nt MAX=100;

int n,i,j,k; float** a; float* x_0; float* x_k;

float precisi on; float w; cout<<\输入精度e:\

cout<

for(j=0;j< n+1;j++) { cin> >a[i][j]; } }

x 0=on e array malloc (n);

\\n\N:\

cout<>x_O[i]; }

x_k=on e_array_malloc( n);

cout<<\输入松弛因子 w (1 >w; float temp; for(k=0;k

{ temp=temp+a[i][j]*x_k[j]; } x_k[i]=a[i][ n]-temp; temp=0;

for(j=i+1;j< n;j++)

{ temp=temp+a[i][j]*x_0[j]; } x_k[i]=(x_k[i]-temp)/a[i][i]; x_k[i]=(1-w)*x_0[i]+w*x_k[i]; } for(i=0;i< n;i++)

{ x_0[i]=x_k[i]-x_0[i]; }

if(matrix_category(x_ 0,n) vprecisi on) { break; }

else { for(i=0;i< n;i++)

{ x_0[i]=x_k[i]; } } }

if(MAX==k) { cout<<\cout<<\cout<<\

迭代不收敛\\n\迭代次数为:\解向量为:\\n\

for(i=0;i< n;i++)

{ cout<<\return 0; }

float *on e_array_malloc(i nt n) { float *a;

a=(float *)malloc(sizeof(float)* n); return a; }

float **two_array_malloc(i nt m,i nt n) { float **a; int i;

a=(float **)malloc(m*sizeof(float *)); for (i=0;i

{ a[i]=(float

*)malloc( n*sizeof(float));

return a; }

}

float matrix_category(float* x,i nt n) { int i; float temp=0; for(i=0;i< n;i++) { temp=temp+fabs(x[i]); } return temp;

结果: 流程图:

nllx

④ 三角分解法 #in clude using n amespace std; int mai n() {

const int N=100;

static double a[N][N],b[N]; int i,j,k,num,p; double m,t,q;

cout<<\请输入矩阵阶数: cin?num;