数值分析课程设计SOR迭代法代码运行可用#includestdio.h#includemath.h#includestdlib.hfloat**a;/*存放A矩阵*/float*b;/*存放b矩阵*/float*x;/*存放x矩阵*/floatp;/*精确度*/floatw;/*松弛因子*/intn;/*未知数个数*/intc;/*最大迭代次数*/intk=1;/*实际迭代次数*/voidSOR(floatxk[]){inti,j;floatt=0.0;floattt=0.0;float*xl;xl=(float*)malloc(sizeof(float)*(n+1));for(i=1;in+1;i++){t=0.0;tt=0.0;for(j=1;ji;j++)t=t+a[i][j]*xl[j];for(j=i;jn+1;j++)tt=tt+a[i][j]*xk[j];xl[i]=xk[i]+w*(b[i]-t-tt)/a[i][i];}t=0.0;for(i=1;in+1;i++){tt=fabs(xl[i]-xk[i]);tt=tt*tt;t+=tt;}t=sqrt(t);for(i=1;in+1;i++)xk[i]=xl[i];if(k+1=c&&tp){k++;SOR(xk);}}voidmain(){inti,j;printf(输入矩阵维数N:\n);scanf(%d,&n);a=(float**)malloc(sizeof(float)*(n+1));for(i=0;in+1;i++)a[i]=(float*)malloc(sizeof(float)*(n+1));printf(输入矩阵A:\n);for(i=1;in+1;i++)for(j=1;jn+1;j++)scanf(%f,&a[i][j]);for(i=1;in+1;i++)for(j=1;jn;j++)if(a[i][j]==0)printf(a[%d][%d]不能为0\n,i,j);b=(float*)malloc(sizeof(float)*(n+1));printf(输入矩阵b:\n);for(i=1;in+1;i++)scanf(%f,&b[i]);x=(float*)malloc(sizeof(float)*(n+1));printf(输入矩阵x:\n);for(i=1;in+1;i++)scanf(%f,&x[i]);printf(输入精确值:\n);scanf(%f,&p);printf(输入最大迭代次数:\n);scanf(%d,&c);printf(输入松弛因子w(0w2):\n);scanf(%f,&w);SOR(x);for(i=1;in+1;i++)printf(%f\n,x[i]);}