好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

数值分析第06次作业.doc

5页
  • 卖家[上传人]:wm****3
  • 文档编号:40846499
  • 上传时间:2018-05-27
  • 文档格式:DOC
  • 文档大小:64.50KB
  • / 5 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 实验 1:题目:题目:计算302152000 8.11200uduu 编程:编程:(1) 建立被积函数文件 f1 function y=f1(x) y=2000*x/(8.1*x*x+1200); (2)调用 f1 函数 1 辛普森公式 a=15; b=30; I=(b-a)*(f1(a)+f1((a+b)/2)+f1(b))/6 >>I = 0.0751 2 梯形公式 a=15; b=30; I=(b-a)*f((a+b)/2) >> I =0.1183结果:结果:1 辛普森公式: I = 0.0751 2 梯形公式: I =0.1183 实验 2:题目:题目:2、用复合梯形公式、复合 Simpson 公式计算积分:1204 1dxx并用剖分区间对误差的影响,取.积分精确值2,4,8,16,32,64,128,256,512n 3.141592653...I编程:编程:(1)建立被积函数文件 f2 function y=f2(x) y=4/(1+x*x); (2)调用 f1 函数 Iexact=3.141592653; a=0;b=1; fprintf('\n 积分精确值 Iexact=3.141592653...');fprintf('\n n I Error\n'); n=1; for k=1:9n=2*n;s=0;h=(b-a)/n;for i=1:n-1x(i)=i*h;s=s+f2(x(i));endI=(f2(a)+2*s+f2(b))*h/2;fprintf('%3.0f %12.9f %12.9f\n',n,I,Iexact-I); end >> Iexact=3.141592653; a=0;b=1; fprintf('\n 积分精确值 Iexact=3.141592653...'); fprintf('\n n I Error\n'); n=1; for k=1:9n=2*n;s=0;g=0;h=(b-a)/n;for i=1:n-1x(i)=i*h;s=s+f(x(i));endfor i=1:nx(i)=i*h;g=g+f(x(i)-h/2);endI=(f(a)+2*s+4*g+f(b))*h/6;fprintf('%3.0f %12.9f %12.9f\n',n,I,Iexact-I); end >>结果:结果:a.复合梯形公式: 积分精确值 Iexact=3.141592653...n I Error2 3.100000000 0.0415926534 3.131176471 0.0104161828 3.138988494 0.00260415916 3.140941612 0.00065104132 3.141429893 0.00016276064 3.141551963 0.000040690 128 3.141582481 0.000010172 256 3.141590110 0.000002543 512 3.141592018 0.000000635 b.复合 simpson 公式: 积分精确值 Iexact=3.141592653...n I Error2 3.141568627 0.0000240264 3.141592502 0.0000001518 3.141592651 0.00000000216 3.141592654 -0.00000000132 3.141592654 -0.00000000164 3.141592654 -0.000000001 128 3.141592654 -0.000000001 256 3.141592654 -0.000000001 512 3.141592654 -0.000000001实验 3:题目:题目:3、用复合梯形公式计算下面积分,取被积函数值以0.80( )f x dx0.4,0.2,0.1.h 下面表格形式给出: x0.00.1 0.20.30.40.50.60.70.8( )f x02.12203.02443.25683.13992.85792.51402.16391.8358编程:编程:x=[0.0 0.1 0.2 0.3 0.4 0.5 0.7 0.8]; y=[0 2.1220 3.0244 3.2568 3.1399 2.8579 2.5140 2.1639 1.8358]; a=0;b=0.8; fprintf('\n h I Error\n'); n=9; for k=1:3s=0;if k>结果:结果:h I Error 0.1 2.940882733 0.200709920 0.2 4.401686777 -1.260094124 0.4 5.627931506 -2.486338853提高题: 用 Romberg 法求函数积分,精度为. 10sin xIdxx0.56e编程:编程:function t=naromberg(fname,a,b,e) naromberg(inline('sin(x)./x'),eps,1,0.5e-6) function t=naromberg(fname,a,b,e)if nargine i=i+1;h=h/2; T(i+1,1)=T(i,1)/2+sum(feval(fname,a+h/2:h:b-h/2+0.001*h))*h/2; for j=1:iT(i+1,j+1)=4^j*T(i+1,j)/(4^j-1)-T(i,j)/(4^j-1);end endT t=T(i+1,j+1); ..>>结果:结果:T =0.920736 0 0 00.939793 0.946146 0 00.944514 0.946087 0.946083 00.945691 0.946083 0.946083 0.946083ans =0.946083。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.