- 5
- 0
- 约5.23千字
- 约 43页
- 2017-02-02 发布于江苏
- 举报
NA-5-2复化求积公式课件精品
第 二 节 复化求积公式 Example 1 Approximate the integral Using the Composite Trapezoidal rule and Composite Simpson’s rule x=eps:0.01:pi; y=sin(x)./x; plot(x,y); legend(f(x)=sin(x)/x); function rs= trapezoid(f,a,b,n) h = (b-a)/n; r= (feval(f,a)+feval(f,b))/2 ; for j = 1:n-1 x=a+j*h ; r= r+ feval(f,x); end rs = r* h; n=8, tp=1.84784230644461 n=16, tp=1.85091414036536 n=32, tp=1.85168137241373 n=64, tp=1.85187313510989 n=128, tp=1.85192107295303 n=256, tp=1.85193305723690 n=512, tp=1.85193605329681 n=1024, tp=1.85193680231110 n=2048, tp=1.85193698956462 n=4096, tp=1.85193703637800 n=8192, tp=1.85193704808136 function rs= simpson(s,a,b,n) h = (b-a)/n; r= feval(s,a)+feval(s,b); for j = 1:2:n-1 x=a+j*h ; r= r+ 4*feval(s,x); end for j = 2:2:n-2 x=a+j*h ; r= r+ 2*feval(s,x); end rs = r*h/3; format long f =inline( sin(x)/x ) ; a = eps; b =pi; n = 8; % eps 是Matlab最小正数 sp = simpson(f, a, b, n) n=8, sp=1.85195370083255 n=16, sp=1.85193808500560 n=32, sp=1.85193711642985 n=64, sp=1.85193705600861 n=128, sp=1.85193705223407 n=256, sp=1.85193705199819 n=512, sp=1.85193705198345 n=1024, sp=1.85193705198253 n=2048, sp=1.85193705198247 n=4096, sp=1.85193705198246 n=8192, sp=1.85193705198247 数值试验结果 用复化Simpson公式求解,当区间分成64份时,计算结果: sp=1.85193705600861 比用复化梯形公式,当区间分成8192份 时的计算结果: tp=1.85193704808136 还要精确。 启发:寻求精度更高的求解方法! 复化梯形、复化 Simpson 公式计算结果对比 n=8, tp=1.84784230644461 n=16, tp=1.85091414036536 n=32, tp=1.851681372
原创力文档

文档评论(0)