您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 3数值计算方法上机实习题
上海电力学院数值计算上机报告课程:现代数值计算题目:数值计算方法上机实习题报告院系:自动化工程学院专业年级:电机与电器学生姓名:黄丽学号:ys1310401009指导教师:黄建雄2013年12月20日数值计算方法上机实习题1.设105dxxxInn,(1)由递推公式nIInn151,从0I的几个近似值出发,计算20I;(2)粗糙估计20I,用nIInn51511,计算0I;(3)分析结果的可靠性及产生此现象的原因(重点分析原因)。程序:(1)由递推公式nIInn151,从0I的几个近似值出发,计算20I;I(0)=0.1820;I(1)=0.0900;I(2)=0.0500;I(3)=0.0833;I(4)=-0.1667;I=0.182;forn=1:20I=(-5)*I+1/n;end故计算结果20I=-3.0666e+10(2)粗糙估计20I,用nIInn51511,计算0I;0095.0560079.01020201020dxxIdxxI=0.008;forn=20:-1:1I=(-1/5)*I+1/(5*n);endI0I=0.1823(3)分析结果的可靠性及产生此现象的原因(重点分析原因)。假设nS的真值为*nS,误差为n,即nnnSS*。对于真值也有nSSnn151**。综合2个递推等式,有15nn,即意味着只要n足够大,按照这种每计算一步误差增长5倍的方式,所得的结果总是不可信的,因此整个算法是数值不稳定的。而第二种方式的误差会以每计算一步缩小到1/5的方式进行,这样的计算结果和实际是很相近的。2.求方程0210xex的近似根,要求41105kkxx,并比较计算量。(1)在[0,1]上用二分法;(2)取初值00x,并用迭代1021xkex;(3)加速迭代的结果;(4)取初值00x,并用牛顿迭代法;(5)分析绝对误差。(1)在[0,1]上用二分法;程序:a=0;b=1.0;i=0;whileabs(b-a)5*1e-4c=(b+a)/2;ifexp(c)+10*c-20b=c;elsea=c;endi=i+1;endc方程的近似根为:x*=(a+b)/2=0.0906。步长为i=11。(2)取初值00x,并用迭代1021xkex;程序:x=0;y=0.1;i=0;whileabs(y-x)5*1e-4y=x;x=(2-exp(x))/10;i=i+1;end方程的近似根为:x=0.0905。步长为i=4。(3)加速迭代的结果;程序:x=0;xx=1;i=0;whileabs(xx-x)5*1e-4y=exp(x)+10*x-2;z=exp(y)+10*y-2;xx=x;x=x-(y-x)^2/(z-2*y+x);i=i+1;endx方程的近似根为:x=0.0995。步长为i=3。(4)取初值00x,并用牛顿迭代法;程序:x=0;y=0.1;i=0;whileabs(y-x)5*1e-4y=x;x=x-(exp(x)+10*x-2)/(exp(x)+10);%diff(exp(x)+10*x-2)=exp(x)+10i=i+1;endxi方程的近似根为:x=0.0905。步长为i=2。(6)分析绝对误差。solve('exp(x)+10*x-2=0')方程的精确解为x=0.0905。3.钢水包使用次数多以后,钢包的容积增大,数据如下:x23456789y6.428.29.589.59.7109.939.991011121314151610.4910.5910.6010.810.610.910.76试从中找出使用次数和容积之间的关系,计算均方差。(注:增速减少,用何种模型)解:(1)设y=f(x)具有指数形式xbaey(a0,b0)。对此式两边取对数,得xbay1lnln。记A=lna,B=bx=[2345678910111213141516];fori=1:15X(i)=1/x(i);endy=[6.428.29.589.59.7109.939.9910.4910.5910.6010.810.610.910.76];fori=1:15Y(i)=log(y(i));endpolyfit(X,Y,1)经计算ans=-1.11072.4578。故方程为1107.14578.2ln4578.211107.1lnbBaAaxy故原方程的系数为1107.16791.11ba故原方程为:xey1107.16791.11(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;fori=1:15a=y(i);b=x(i);c=c+(a-f(b))^2;endaverge=c/15结果:averge=0.05944.设410100141010014101101410010141001014A,625250b,bxA分析下列迭代法的收敛性,并求42110kkxx的近似解及相应的迭代次数。(1)JACOBI迭代;以文件名math4a.m保存。functionmath4aA=[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))endfunctiontx=jacobi(A,b,imax,x0,tol)%初始值x0,次数imax,精度toldel=10^-10;tx=[x0];n=length(x0);fori=1:ndg=A(i,i);ifabs(dg)deldisp('对角元太小');returnendendfork=1:imax%jacobi循环fori=1:nsm=b(i);forj=1:nifj~=ism=sm-A(i,j)*x0(j);endendx(i)=sm/A(i,i);endtx=[tx;x];ifnorm(x-x0)tolreturnelsex0=x;endend近似解y为:10.0000000.0000000.0000000.0000000.0000000.00000020.0000001.250000-0.5000001.250000-0.5000001.50000030.6250001.0000000.5000001.0000000.5000001.25000040.5000001.6562500.3125001.6562500.3125001.75000050.8281251.5312500.7656251.5312500.7656251.65625060.7656251.8398440.6796881.8398440.6796881.88281370.9199221.7812500.8906251.7812500.8906251.83984480.8906251.9252930.8505861.9252930.8505861.94531390.9626461.8979490.9489751.8979490.9489751.925293100.9489751.9651490.9302981.9651490.9302981.974487110.9825741.9523930.9761961.9523930.9761961.965149120.9761961.9837420.9674841.9837420.9674841.988098130.9918711.9777910.9888951.9777910.9888951.983742140.9888951.9924150.9848311.9924150.9848311.994448150.9962081.9896390.9948201.9896390.9948201.992415160.9948201.9964620.9929231.9964620.9929231.997410170.9982311.9951670.9975831.9951670.9975831.996462180.9975831.9983490.9966991.9983490.9966991.998792190.9991751.9977450.9988731.9977450.9988731.998349200.9988731.9992300.9984601.9992300.9984601.999436210.9996151.9989480.9994741.9989480.9994741.999230220.9994741.9996410.9992821.9996410.9992821.999737230.9998201.9995090.9997551.9995090.9997551.999641240.9997551.9998320.9996651.9998320.9996651.999877250.9999161.9997710.9998861.9997710.9998861.999832260.9998861.9999220.9998441.9999220.9998441.999943270.9999611.9998930.9999471.9998930.9999471.999922280.9999471.9999640.9999271.9999640.9999271.999973290.9999821.9999500.9999751.9999500.9999751.999964(2)GAUSS-SEIDEL迭代;以文件名math4b.m保存。functionmath4bA=[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=gs(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))endfunctiontx=gs(A,b,imax,x0,tol)%初始值x0,次数imax,精度toldel=10^-10;tx=[x0];n=length(x0);fori=1:ndg=A(i,i);ifabs(dg)deldisp('对角元太小');returnendendfork=1:imax%gs循环x=x0;fori=1:nsm=b(i);forj=1:nifj~=ism=sm-A(i,j)*x(j);endendx(i)=sm/A(i,i);endtx=[tx;x];ifnorm(x-x0)tolreturnelsex0=x;endend近似解y为:10.0000000.0000000.0000000.0000000.0000000.00000020.0000001.250000-0.1875001.2031250.1132811.48144530.6132811.3847660.5173341.5609740.6067961.78103340.7364351.7151410.7642871.
本文标题:3数值计算方法上机实习题
链接地址:https://www.777doc.com/doc-2921506 .html