(1)用牛顿-科次公式求的近似值(n=1,2..,8) 下面是代码:(老师写的) cotes=[12,12,0,0,0,0,0,0,0; 16,23,16,0,0,0,0,0,0; 18,38,38,18,0,0,0,0,0; 790,1645,215,1645,790,0,0,0,0; 19288,75288,50288,50288,75288,19288,0,0,0; 41840,216840,27840,272840,27840,216840,41840,0,0; 751,3577,1323,2989,2989,1323,3577,751,0; 989,5888,-928,,-4540,,-928,5888,989]; a=inp t( 积分上限: ); b=inp t( 积分下限: ); disp( 阶数 牛顿迭代科特斯积值 ) for n=1:8 s=0; h=(b-a)n; for k=1:n+1 x(k)=a+(k-1)*h; y(k)=f(x(k)); s=s+cotes(n,k)*y(k); end s=s*(b-a); fprintf( n=%d i=%6.5fn ,n,s) end (2)计算曲边梯形面积,可用内接梯形的面积sn来进行逼近,用动画形象描述这一逼近的过程: (按照定积分的定义,有) 下面是用matlab设计一幅动画,模拟sn-i的过程:(自己写的) f.m的m文件代码: f nction y=f(x) y=exp(x); cpp.m文件代码: cla reset clear clc ff=sym( exp(x) ); aa=int(ff,0,2) plot(0:0.1:10,s bs(aa)) hold on a=0; b=2; n=inp t( 请输入初始的n值: ) sss=inp t( 请输入想要控制的精度: ) s=0; ss=s bs(aa)-s; while ss=sss for i=1:n-1 h=(b-a)n; x=a+i*h; s=s+f(x)*h; ss=s bs(aa)-s; end fprintf( n=%d s=%6.5fn ,n,s) plot(0:0.1:100,s) m(n)=getframe; hold on n=n+20; s=0;