资源描述:
《昆工数值分析上机作业.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、国土资源工程学院测绘工程课题一迭代格式的比较要求:1、编制一个程序进行运算,最后打印出每种迭代格式的敛散情况;①、建立迭代程序的M文件:function[k,pc,xk]=diedail(xO,k)x(1)=x0fori=1:kx(i+1)=funi(x(i));pc=abs(x(i+l)-x(i));%偏差i=i+l;xk=x(i);%第1<次迭代的结果[(i-1)pcxk]endp=[(i-1)pcxk];%输出迭代次数、偏差、第k次迭代的结果②、对于不同的迭代式子建立不同的funkm文件(1)3x+1建立迭代式子(1)的M文件:functio
2、nyl=funl(x)yl=(3*x+l)/xA2;在matlab命令窗口中运行以下命令»[k,pc,xk]二dieda订(0.7,10)%初值是0.7,迭代10次X二0.7000X=0.70006.3265ans1.00005.62656.3265X=0.70006.32650.4992ans2.00005.82740.4992X二0.70006.32650.499210.0231ans3.00009.523910.02310.70006.32650.499210.02310.3093ans4.00009.71380.3093x—0.70006.
3、32650.499210.02310.309320.1559ans—5.000019.846620.1559x—0.70006.32650.499210.02310.309320.15590.1513ans=6.000020.00460.1513x—0.70006.32650.499210.02310.309320.15590.151363.5112ans=1.000063.359963.5112x—0.70006.32650.499210.02310.309320.15590.151363.51120.0475ans=8.000063.46380
4、.0475x—0.70006.32650.499210.02310.309320.15590.151363.51120.0475506.6983ans=9.0000506.6508506.6983x—0.70006.32650.499210.02310.309320.15590.151363.51120.0475506.69830.0059ans=10.0000506.69240.0059k=10pc二506.6924xk=0.0059由以上结果可知迭代式(1)是发散的。F—1(2)X=—-3建立迭代式子(2)的M文件:functionyl=fun
5、l(x)yl=(x"3-l)/3;在matlab命令窗口中运行以下命令»[k,pc,xk]二dieda订(0.6,5)%初值0.6,迭代5次X二0.6000X=0.6000-0.2613ans—1.00000.8613-0.2613X=0.6000-0.2613-0.3393ans二2.00000.0779-0.3393X二0.6000-0.2613-0.3393-0.3464ans—3.00000.0071-0.3464X二0.6000-0.2613-0.3393-0.3464ans4.00000.0008-0.3472X二0.6000-0.26
6、13-0.3393-0.3464-0.3472-0.3472-0.34733HS二5.00000.0001-0.3473k=5pc—9.9907e-005xk=-0.3473由以上结果可知迭代式(2)是收敛的。(2)X=(3x+1)%建立迭代式子(3)的M文件:functiony1=funl(x)yl=(3*x+l)A(1/3);在matlab命令窗口中运行以下命令:»[k,pc,xk]二dieda订(0.9,12)%初值0.9,迭代12次结果为0.60000.6000-0.2613cins—kOOOO0.8613-0.2613X=0.6000-0
7、.2613-0.3393ans—2.00000.0779-0.3393X二0.6000-0.2613-0.3393-0.3464ans3.00000.0071-0.3464X二0.6000-0.2613-0.3393-0.3464-0.3472ans—4.00000.0008-0.3472X二0.6000-0.2613-0.3393-0.3464-0.3472-0.3473ans—5.00000.0001-0.3473pc=9.9907e-005xk二-0.3473>>[k,pc,xk]=diedail(0.9,12)%初值0.9,迭代12次0.9
8、000X二0.90001.5467ans二1.00000.64671.5467X=0.90001.54671.7800an