收藏 分销(赏)

simpson法求积分.doc

上传人:人****来 文档编号:4330440 上传时间:2024-09-06 格式:DOC 页数:1 大小:20.50KB 下载积分:5 金币
下载 相关 举报
simpson法求积分.doc_第1页
第1页 / 共1页
本文档共1页,全文阅读请下载到手机保存,查看更方便
资源描述
主程序为: clear;clc; n=4;a=0;b=1; syms x t f=(4*x^3+5*x^2-2*x+5)/(8*(x+1)^2); g=1/(1+t);sou=1/(x+1)^2; h=(b-a)/n;l=2*n+1;xi=a:h/2:b; c=repmat([2,4],1,n-1);c=[1,c,2,1]; %Simpson插值的各项系数 u=c.*subs(g,xi);u=repmat(u,l,1); v=xi'*c; u=h*(u-v)/6-eye(l); w=-(subs(f,xi))'; [s,yi]=columngauss(u,w); %调用列主元Gauss消去法解方程组 if ~s disp('Error!There is something wrong.'); else disp('When x=');disp(xi); disp('The discrete solution of y(x) is:');disp(yi'); end sp=myspline(xi,yi'); %调用三次样条插值函数 xk=0:0.001:1; sk=subs(sou,xk); for i=1:length(xk) r=find(xi(2:l)>=xk(i),1,'first'); yk(i)=subs(sp(r),xk(i)); %计算S(xk) end es=max(abs(yk-sk)); disp(['The maximum error is: ',num2str(es)]); plot(xk,sk,'r',xk,yk); %画图 title('Solve equation by numerical intergration'); legend('Acurate solution','Approximate solution'); xlabel('x');ylabel('y(x)'); grid on;
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服