3数值计算方法上机实习题要点文档格式.docx
- 文档编号:22024563
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:37
- 大小:336.34KB
3数值计算方法上机实习题要点文档格式.docx
《3数值计算方法上机实习题要点文档格式.docx》由会员分享,可在线阅读,更多相关《3数值计算方法上机实习题要点文档格式.docx(37页珍藏版)》请在冰豆网上搜索。
I(4)=-0.1667;
I=0.182;
forn=1:
20
I=(-5)*I+1/n;
end
故计算结果
=-3.0666e+10
I=0.008;
forn=20:
-1:
1
I=(-1/5)*I+1/(5*n);
I
=0.1823
假设
的真值为
,误差为
,即
。
对于真值也有
综合2个递推等式,有
,即意味着只要n足够大,按照这种每计算一步误差增长5倍的方式,所得的结果总是不可信的,因此整个算法是数值不稳定的。
而第二种方式的误差会以每计算一步缩小到1/5的方式进行,这样的计算结果和实际是很相近的。
2.求方程
的近似根,要求
,并比较计算量。
(1)在[0,1]上用二分法;
(2)取初值
,并用迭代
(3)加速迭代的结果;
(4)取初值
,并用牛顿迭代法;
(5)分析绝对误差。
程序:
a=0;
b=1.0;
i=0;
whileabs(b-a)>
5*1e-4
c=(b+a)/2;
ifexp(c)+10*c-2>
b=c;
elsea=c;
end
i=i+1;
end
c
方程的近似根为:
x*=(a+b)/2=0.0906。
步长为i=11。
程序:
x=0;
y=0.1;
whileabs(y-x)>
y=x;
x=(2-exp(x))/10;
x=0.0905。
步长为i=4。
x=0;
xx=1;
whileabs(xx-x)>
y=exp(x)+10*x-2;
z=exp(y)+10*y-2;
xx=x;
x=x-(y-x)^2/(z-2*y+x);
x
x=0.0995。
步长为i=3。
x=x-(exp(x)+10*x-2)/(exp(x)+10);
%diff(exp(x)+10*x-2)=exp(x)+10
end
i
x=0.0905。
步长为i=2。
(6)分析绝对误差。
solve('
exp(x)+10*x-2=0'
)
方程的精确解为x=0.0905。
3.钢水包使用次数多以后,钢包的容积增大,数据如下:
2
3
4
5
6
7
8
9
y
6.42
8.2
9.58
9.5
9.7
10
9.93
9.99
11
12
13
14
15
16
10.49
10.59
10.60
10.8
10.6
10.9
10.76
试从中找出使用次数和容积之间的关系,计算均方差。
(注:
增速减少,用何种模型)
解:
(1)设y=f(x)具有指数形式
(a>
0,b<
0)。
对此式两边取对数,得
记A=lna,B=b
x=[2345678910111213141516];
fori=1:
X(i)=1/x(i);
y=[6.428.29.589.59.7109.939.9910.4910.5910.6010.810.610.910.76];
Y(i)=log(y(i));
polyfit(X,Y,1)
经计算ans=-1.11072.4578。
故方程为
故原方程的系数为
故原方程为:
(2)计算均方差:
x=[2:
16];
y=[6.428.29.589.59.7109.939.9910.4910.5910.6010.810.610.910.76];
f(x)=11.6791*exp(-1.1107./x);
c=0;
a=y(i);
b=x(i);
c=c+(a-f(b))^2;
averge=c/15
结果:
averge=0.0594
4.设
分析下列迭代法的收敛性,并求
的近似解及相应的迭代次数。
(1)JACOBI迭代;
以文件名math4a.m保存。
functionmath4a
A=[4-10-100;
-14-10-10;
0-14-10-1;
-10-14-10;
0-10-14-1;
00-10-14];
b=[05-25-26];
x0=[000000];
imax=100;
tol=10^-4;
tx=jacobi(A,b,imax,x0,tol);
forj=1:
size(tx,1)
fprintf('
%d%f%f%f%f%f%f\n'
j,tx(j,1),tx(j,2),tx(j,3),tx(j,4),tx(j,5),tx(j,6))
functiontx=jacobi(A,b,imax,x0,tol)%初始值x0,次数imax,精度tol
del=10^-10;
tx=[x0];
n=length(x0);
n
dg=A(i,i);
ifabs(dg)<
del
disp('
对角元太小'
);
return
fork=1:
imax%jacobi循环
fori=1:
sm=b(i);
forj=1:
ifj~=i
sm=sm-A(i,j)*x0(j);
x(i)=sm/A(i,i);
tx=[tx;
x];
ifnorm(x-x0)<
tol
else
x0=x;
近似解y为:
10.0000000.0000000.0000000.0000000.0000000.000000
20.0000001.250000-0.5000001.250000-0.5000001.500000
30.6250001.0000000.5000001.0000000.5000001.250000
40.5000001.6562500.3125001.6562500.3125001.750000
50.8281251.5312500.7656251.5312500.7656251.656250
60.7656251.8398440.6796881.8398440.6796881.882813
70.9199221.7812500.8906251.7812500.8906251.839844
80.8906251.9252930.8505861.9252930.8505861.945313
90.9626461.8979490.9489751.8979490.9489751.925293
100.9489751.9651490.9302981.9651490.9302981.974487
110.9825741.9523930.9761961.9523930.9761961.965149
120.9761961.9837420.9674841.9837420.9674841.988098
130.9918711.9777910.9888951.9777910.9888951.983742
140.9888951.9924150.9848311.9924150.9848311.994448
150.9962081.9896390.9948201.9896390.9948201.992415
160.9948201.9964620.9929231.9964620.9929231.997410
170.9982311.9951670.9975831.9951670.9975831.996462
180.9975831.9983490.9966991.9983490.9966991.998792
190.9991751.9977450.9988731.9977450.9988731.998349
200.9988731.9992300.9984601.9992300.9984601.999436
210.9996151.9989480.9994741.9989480.9994741.999230
220.9994741.9996410.9992821.9996410.9992821.999737
230.9998201.9995090.9997551.9995090.9997551.999641
240.9997551.9998320.9996651.9998320.9996651.999877
250.9999161.9997710.9998861.9997710.9998861.999832
260.9998861.9999220.9998441.9999220.9998441.999943
270.9999611.9998930.9999471.9998930.9999471.999922
280.9999471.9999640.9999271.9999640.9999271.999973
290.9999821.9999500.9999751.9999500.9999751.999964
(2)GAUSS-SEIDEL迭代;
以文件名math4b.m保存。
functionmath4b
tx=gs(A,b,imax,x0,tol);
fprintf('
functiontx=gs(A,b,imax,x0,tol)%初始值x0,次数imax,精度tol
del=10^-10;
tx=[x0];
fork=1:
imax%gs循环
x=x0;
sm=sm-A(i,j)*x(j);
20.0000001.250000-0.1875001.2031250.1132811.481445
30.6132811.3847660.5173341.5609740.6067961.781033
40.7364351.7151410.7642871.7768800.8182631.895638
50.8730051.8638890.8841021.8938430.9133421.949361
60.9394331.9342190.9443561.9492830.9582161.975643
70.9708751.9683620.9733221.9756030.9799021.988306
80.9859911.9848040.9871781.9882680.9903441.994381
90.9932681.9926980.9938371.9943620.9953601.997299
100.9967651.9964900.9970381.9972910.9977701.998702
110.9984451.9983130.9985771.9986980.9989281.999376
120.9992531.9991890.9993161.9993740.9994851.999700
130.9996411.9996100.9996711.9996990.9997521.999856
140.9998271.9998130.9998421.9998550.9998811.999931
150.9999171.9999100.9999241.9999310.9999431.999967
160.9999601.9999570.9999641.9999670.9999731.999984
(3)SOR迭代(
)。
以文件名math4c.m保存。
functionmath4c
w0=[1.3341.950.95];
w=w0(i);
tx=sor(A,b,imax,x0,tol,w);
\n'
functiontx=sor(A,b,imax,x0,tol,w)%初始值x0,次数imax,精度tol,松弛因子w
imax%SOR循环
x(i)=w*x(i)+(1-w)*x0(i);
w=1.334时的近似解y:
20.0000001.667500-0.1108891.6305190.4328892.108387
31.0998891.5847551.1454782.0161051.0924492.043147
40.8335242.1625211.0253721.9783941.0305072.004224
51.1025981.9985700.9852522.0466881.0063131.995776
60.9808261.9912701.0161761.9855120.9887402.003050
70.9986612.0041090.9921531.9980201.0054881.998194
81.0011571.9982271.0007672.0031330.9980182.000198
91.0000672.0002101.0009251.9986231.0003392.000355
100.9995882.0002140.9994222.0002431.0001581.999741
111.0002901.9998851.0001492.0001180.9998622.000090
120.9999042.0000101.0000231.9998901.0000431.999992
130.9999992.0000180.9999592.0000371.0000011.999990
141.0000191.9999871.0000182.0000000.9999922.000007
w=1.95时的近似解y:
20.0000002.4375000.2132812.5414751.4522503.736947
32.4272502.1171062.9152023.3355172.1252771.832135
40.3522663.0552130.2642040.605361-0.3163181.159066
51.4498770.216457-0.2603122.2881151.1115262.238853
6-0.1564042.5705852.7323542.0614351.3186012.772930
72.4066943.1435480.3184972.4504851.8512231.348455
80.4407320.7237240.9272271.678891-0.9050161.654796
90.7525802.1276730.8065471.1614332.2949172.864907
100.8884882.3613131.3727613.5552701.1258051.421389
112.0402702.4069361.3203791.2471400.4297742.427880
12-0.1568940.9276250.0144291.3927800.9315031.079656
131.2802472.6415191.5043452.9259561.3805483.305712
141.4979092.0646731.6403381.8607551.2386601.188085
150.4906332.118756-0.0141181.5059300.1944991.884254
161.3009341.1468231.2502032.3453631.4612412.456788
170.4665542.8972931.5907861.9247131.1852331.944361
181.9075021.9682880.3594672.2919710.9237811.703441
190.2647501.3222761.2758791.4615270.3349392.092005
201.1055922.5055880.7667362.1250921.9841172.278636
211.2071441.9867151.4119422.6627240.5175261.700911
221.1198142.0366460.8037921.0979640.8906672.135183
230.4642991.5550810.5956592.3453631.1212351.733562
241.4603832.5090951.6707842.2824511.1408172.648772
250.9485151.8869160.7615981.6590000.9611341.248499
260.8275451.8881900.6393802.0451290.6380592.361678
271.1313251.8179921.4521782.0651391.4631892.102648
280.8182672.5305540.9108722.0318780.8841971.802581
291.4468321.6139000.8157472.0412690.8456662.022487
300.4074051.9128441.1636331.6764370.9573542.037619
311.3627402.3186160.8604762.3954121.4069412.094628
321.0034861.8293811.2882651.9649710.5592831.835783
330.8964352.0372800.6471901.5959451.1598232.061924
340.9
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数值 计算方法 上机 实习 要点