昆工数值分析上机作业.docx
《昆工数值分析上机作业.docx》由会员分享,可在线阅读,更多相关《昆工数值分析上机作业.docx(30页珍藏版)》请在冰豆网上搜索。
昆工数值分析上机作业
国土资源工程学院测绘工程
课题一迭代格式的比较
要求:
1、编制一个程序进行运算,最后打印出每种迭代格式的敛散情况;
、建立迭代程序的M文件:
function[k,pc,xk]=diedail(x0,k)
x
(1)=x0
fori=1:
k
x(i+1)=funl(x(i));
pc=abs(x(i+1)-x(i));%偏差
i=i+1;
xk=x(i);%第k次迭代的结果
[(i-1)pcxk]
end
p=[(i-1)pcxk];%输出迭代次数、偏差、第k次迭代的结果
、对于不同的迭代式子建立不同的funl.m文件
(1)
建立迭代式子
(1)的M文件:
functiony1=funl(x)
y1=(3*x+1)/x^2;
在matlab命令窗口中运行以下命令
>>[k,pc,xk]=diedail(0.7,10)%初值是0.7,迭代10次
x=
0.7000
x=
0.70006.3265
ans=
1.00005.62656.3265
x=
0.70006.32650.4992
ans=
2.00005.82740.4992
x=
0.70006.32650.499210.0231
ans=
3.00009.523910.0231
x=
0.70006.32650.499210.02310.3093
ans=
4.00009.71380.3093
x=
0.70006.32650.499210.02310.309320.1559
ans=
5.000019.846620.1559
x=
0.70006.32650.499210.02310.309320.15590.1513
ans=
6.000020.00460.1513
x=
0.70006.32650.499210.02310.309320.15590.151363.5112
ans=
7.000063.359963.5112
x=
0.70006.32650.499210.02310.309320.15590.151363.51120.0475
ans=
8.000063.46380.0475
x=
0.70006.32650.499210.02310.309320.15590.151363.51120.0475506.6983
ans=
9.0000506.6508506.6983
x=
0.70006.32650.499210.02310.309320.15590.151363.51120.0475506.69830.0059
ans=
10.0000506.69240.0059
k=
10
pc=
506.6924
xk=
0.0059
由以上结果可知迭代式
(1)是发散的。
(2)
建立迭代式子
(2)的M文件:
functiony1=funl(x)
y1=(x^3-1)/3;
在matlab命令窗口中运行以下命令
>>[k,pc,xk]=diedail(0.6,5)%初值0.6,迭代5次
x=
0.6000
x=
0.6000-0.2613
ans=
1.00000.8613-0.2613
x=
0.6000-0.2613-0.3393
ans=
2.00000.0779-0.3393
x=
0.6000-0.2613-0.3393-0.3464
ans=
3.00000.0071-0.3464
x=
0.6000-0.2613-0.3393-0.3464-0.3472
ans=
4.00000.0008-0.3472
x=
0.6000-0.2613-0.3393-0.3464-0.3472-0.3473
ans=
5.00000.0001-0.3473
k=
5
pc=
9.9907e-005
xk=
-0.3473
由以上结果可知迭代式
(2)是收敛的。
(3)
建立迭代式子(3)的M文件:
functiony1=funl(x)
y1=(3*x+1)^(1/3);
在matlab命令窗口中运行以下命令:
>>[k,pc,xk]=diedail(0.9,12)%初值0.9,迭代12次
结果为
x=
0.6000
x=
0.6000-0.2613
ans=
1.00000.8613-0.2613
x=
0.6000-0.2613-0.3393
ans=
2.00000.0779-0.3393
x=
0.6000-0.2613-0.3393-0.3464
ans=
3.00000.0071-0.3464
x=
0.6000-0.2613-0.3393-0.3464-0.3472
ans=
4.00000.0008-0.3472
x=
0.6000-0.2613-0.3393-0.3464-0.3472-0.3473
ans=
5.00000.0001-0.3473
k=
5
pc=
9.9907e-005
xk=
-0.3473
>>[k,pc,xk]=diedail(0.9,12)%初值0.9,迭代12次
x=
0.9000
x=
0.90001.5467
ans=
1.00000.64671.5467
x=
0.90001.54671.7800
ans=
2.00000.23341.7800
x=
0.90001.54671.78001.8508
ans=
3.00000.07081.8508
x=
0.90001.54671.78001.85081.8713
ans=
4.00000.02041.8713
x=
0.90001.54671.78001.85081.87131.8771
ans=
5.00000.00581.8771
x=
0.90001.54671.78001.85081.87131.87711.8787
ans=
6.00000.00171.8787
x=
0.90001.54671.78001.85081.87131.87711.87871.8792
ans=
7.00000.00051.8792
x=
0.90001.54671.78001.85081.87131.87711.87871.87921.8793
ans=
8.00000.00011.8793
x=
0.90001.54671.78001.85081.87131.87711.87871.87921.87931.8794
ans=
9.00000.00001.8794
x=
0.90001.54671.78001.85081.87131.87711.87871.87921.87931.87941.8794
ans=
10.00000.00001.8794
x=
0.90001.54671.78001.85081.87131.87711.87871.87921.87931.87941.87941.8794
ans=
11.00000.00001.8794
x=
0.90001.54671.78001.85081.87131.87711.87871.87921.87931.87941.87941.87941.8794
ans=
12.00000.00001.8794
k=
12
pc=
8.5033e-007
xk=
1.8794
由以上结果可知迭代式(3)是收敛的。
(4)
建立迭代式子(4)的M文件:
functiony1=funl(x)
y1=1/(x^2-3);
在matlab命令窗口中运行以下命令:
>>[k,pc,xk]=diedail(0.4,15)%初值0.4,迭代15次
x=
0.4000
x=
0.4000-0.3521
ans=
1.00000.7521-0.3521
x=
0.4000-0.3521-0.3477
ans=
2.00000.0044-0.3477
x=
0.4000-0.3521-0.3477-0.3473
ans=
3.00000.0004-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473
ans=
4.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473
ans=
5.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473
ans=
6.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
7.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
8.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
9.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
10.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
11.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
12.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
13.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
14.00000.0000-0.3473
x=
0.4000-0.3521-0.3477-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
15.00000.0000-0.3473
k=
15
pc=
5.5511e-017
xk=
-0.3473
由以上结果可知迭代式(4)是收敛的。
(5)
建立迭代式子(5)的M文件:
functiony1=funl(x)
y1=(3+1/x)^(1/2);
在matlab命令窗口中运行以下命令:
>>[k,pc,xk]=diedail(0.6,22)%初值0.6,迭代22次
x=
0.6000
x=
0.60002.1602
ans=
1.00001.56022.1602
x=
0.60002.16021.8609
ans=
2.00000.29941.8609
x=
0.60002.16021.86091.8808
ans=
3.00000.01991.8808
x=
0.60002.16021.86091.88081.8793
ans=
4.00000.00151.8793
x=
0.60002.16021.86091.88081.87931.8794
ans=
5.00000.00011.8794
x=
0.60002.16021.86091.88081.87931.87941.8794
ans=
6.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.8794
ans=
7.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.8794
ans=
8.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.8794
ans=
9.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.8794
ans=
10.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.8794
ans=
11.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.8794
ans=
12.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.8794
ans=
13.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
ans=
14.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
ans=
15.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
ans=
16.00000.00001.8794
x=
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
ans=
17.00000.00001.8794
x=
Columns1through18
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
Column19
1.8794
ans=
18.00000.00001.8794
x=
Columns1through18
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
Columns19through20
1.87941.8794
ans=
19.00000.00001.8794
x=
Columns1through18
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
Columns19through21
1.87941.87941.8794
ans=
20.00000.00001.8794
x=
Columns1through18
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
Columns19through22
1.87941.87941.87941.8794
ans=
21.00000.00001.8794
x=
Columns1through18
0.60002.16021.86091.88081.87931.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.87941.8794
Columns19through23
1.87941.87941.87941.87941.8794
ans=
22.00000.00001.8794
k=
22
pc=
2.2204e-016
xk=
1.8794
由以上结果可知迭代式(5)是收敛的。
(6)
建立迭代式子(6)的M文件:
functiony1=funl(x)
y1=x-(1/3)*((x^3-3*x-1)/(x^2-1));
在matlab命令窗口中运行以下命令:
>>[k,pc,xk]=diedail(0.5,50)%初值0.5,迭代50次
x=
0.5000
x=
0.5000-0.5556
ans=
1.00001.0556-0.5556
x=
0.5000-0.5556-0.3168
ans=
2.00000.2388-0.3168
x=
0.5000-0.5556-0.3168-0.3470
ans=
3.00000.0302-0.3470
x=
0.5000-0.5556-0.3168-0.3470-0.3473
ans=
4.00000.0003-0.3473
x=
0.5000-0.5556-0.3168-0.3470-0.3473-0.3473
ans=
5.00000.0000-0.3473
x=
0.5000-0.5556-0.3168-0.3470-0.3473-0.3473-0.3473
ans=
6.00000.0000-0.3473
x=
0.5000-0.5556-0.3168-0.3470-0.3473-0.3473-0.3473-0.3473
ans=
7.00000.0000-0.3473
x=
0.5000-0.5556-0.3168-0.3470-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
8.00000.0000-0.3473
x=
0.5000-0.5556-0.3168-0.3470-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
9.00000.0000-0.3473
x=
0.5000-0.5556-0.3168-0.3470-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
10.00000.0000-0.3473
x=
0.5000-0.5556-0.3168-0.3470-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
11.00000.0000-0.3473
x=
0.5000-0.5556-0.3168-0.3470-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473-0.3473
ans=
12.00000.0000