Jacobi迭代法(1)Jacobi迭代法的思想Jacobi迭代法的具体算法如下:对方程组Ax=b,其中A为非奇异矩阵。设0(1,2,,)iiain≠=,并将A写为三部分:121,1111212,12221,11,21,12,100000000nnnnnnnnnnnnnnaaaaaaaaAaaaaaaaDLU−−−−−−−−−⎡⎤⎡⎤⎡⎤⎢⎥⎢⎥−−⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥=−−⎢⎥⎢⎥⎢⎥−−−⎢⎥⎢⎥⎢⎥⎣⎦⎢⎥⎢⎥−−−⎣⎦⎣⎦=−−##%%##%于是()AxbDLUxb=⇔−−=即11()xDLUxDb−−=++所以解Ax=b的基本迭代公式为(0)(0)(0)1(1)()1(,,),()/(1,2,,)(0,1,).nnkkiiijjiijjixxxxbaxaink+=≠⎧=⎪⎪⎨=−==⎪⎪⎩∑(2)Jacobi迭代法的C语言编程下面是Jacobi迭代的C语言编程实例,程序功能是求解线性方程组Ax=b,要求迭代精度小于10-6。其中123832204111,,33631236xAxxbx−⎡⎤⎡⎤⎡⎤⎢⎥⎢⎥⎢⎥=−==⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦⎣⎦#includestdio.h#includemath.h#includeiostream.h#defineN3doubleCompare(doublea[N],doubleb[N]){doublec=0;inti;for(i=0;i=N-1;i++)c+=fabs(a[i]-b[i]);returnc;}voidJacobi(doubleA[N][N],doublex[N],doubleb[N],doubleprecesion){inti,j,k;doublex2[N],sum;for(i=0;i=N-1;i++)x2[i]=x[i];//将初始迭代向量x=[0,0,0,0]赋给x2k=1;//k为迭代次数while(1){for(i=0;i=N-1;i++){sum=0;for(j=0;j=N-1;j++){if(j!=i)sum+=A[i][j]*x2[j];}x[i]=(b[i]-sum)/A[i][i];//以x2为基础进行迭代求出x}//输出每一次迭代的结果printf(第%d次迭代:\n,k);printf(x2=);for(i=0;i=N-1;i++)printf(%lf,x2[i]);printf(\n);printf(x=);for(i=0;i=N-1;i++)printf(%lf,x[i]);printf(\n);//判断是否达到迭代精度if(Compare(x2,x)=precesion){printf(达到迭代精度的方程组的解为:\n);printf(x=);for(i=0;i=N-1;i++)printf(%lf,x[i]);printf(\n);break;}else{for(i=0;i=N-1;i++)x2[i]=x[i];//将第k次迭代计算得到的向量x赋给x2k++;continue;}}}voidmain(){doubleA[N][N]={{8,-3,2},{4,11,-1},{6,3,12}},x[N]={0},b[N]={20,33,36};Jacobi(A,x,b,1e-6);}程序运行结果:迭代17次达到所需精度10-6