资源描述:
《研究生数值分析课后题上机编程部分答案.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、...2009级研究生《数值分析》上机作业院系电气工程学院专业控制理论与控制工程马凯指导教师代新敏2009年12月29日.......第一题(二问):超松弛法求方程组根1.解题理论依据或方法应用条件:超松弛算法是在GS方法已求出x(m),x(m-1)的基础上,经过重新组合得到新序列。如能恰当选择松弛因子ω,收敛速度会比较快。当ω>1时,称为超松弛法,可以用来加速收敛。其具体算法为:2.计算程序(使用软件:VC):#include#definew1.4main(){floata[10][10]={{0,0,0,0,0,0,0,0,0,0},{0,12.38412,2
2、.115237,-1.061074,1.112336,-0.113584,0.718719,1.742382,3.067813,-2.031743},{0,2.115237,19.141823,-3.125432,-1.012345,2.189736,1.563849,-0.784165,1.112348,3.123124},{0,-1.061074,-3.125432,15.567914,3.123848,2.031454,1.836742,-1.056781,0.336993,-1.010103},{0,1.112336,-1.012345,3.123848,27.108437
3、,4.101011,-3.741856,2.101023,-0.71828,-0.037585},{0,-0.113584,2.189736,2.031454,4.101011,19.897918,0.431637,-3.111223,2.121314,1.784317},0,0.718719,1.563849,1.836742,-3.741856,0.431637,9.789365,-0.103458,-1.103456,0.238417},{0,1.742382,-0.784165,-1.056781,2.101023,-3.111223,-0.103458,14.713846
4、5,3.123789,-2.213474},{0,3.067813,1.112348,0.336993,-0.71828,2.121314,-1.103456,3.123789,30.719334,4.446782},{0,-2.031743,3.123124,-1.010103,-0.037585,1.784317,0.238417,-2.213474,4.446782,40.00001}};floatb[10][1]={{0},{2.1874369},{33.992318},{-25.173417},{0.84671695},{1.784317},{-86.612343},{1
5、.1101230},{4.719345},{-5.6784392}};floatx[10][10]={{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}};/*由x(0)=0得到其第一列全为零*/floatsum1=0,sum2=0;inti,m,j;for(m=1;m<=9;m++)for(i=1;i<=9;i++){sum1=0;.......for(j=1;j<=(i-1);j++)sum1+=(-a[i][j]/a[i][i])*x[j][m];/*计算第一个累加和*/sum2=0;for(j=(i+1);j<=9;j++)sum2+=(-a[i
6、][j]/a[i][i])*x[j][m-1];/*计算第二个累加和*/x[i][m]=(1-w)*x[i][m-1]+w*(sum1+sum2+b[i][0]/a[i][i]);/*用SOR方法计算*/}printf("x1为:%lf",x[1][9]);printf("x2为:%lf",x[2][9]);printf("x3为:%lf",x[3][9]);printf("x4为:%lf",x[4][9]);printf("x5为:%lf",x[5][9]);printf("x6为:%lf",x[6][9]);printf("x7为:%lf",x[7]
7、[9]);printf("x8为:%lf",x[8][9]);printf("x9为:%lf",x[9][9]);}3.计算结果4.问题讨论(误差分析、上机出现情况等)这道题目是所有题目中编写最顺利的,一次即顺利得出结果,当然这道题目还是有应该注意到地方,一是注意两个求和的清零,二是注意下标,不要弄混行标和列标。第一题(三问):列主元素法求方程组根.......1.解题理论依据或方法应用条件:所谓列主元消去法是,对矩阵作恰当的调整,选取绝对值最大的元素作为主元