資源描述:
《matlab求解積分問題探討》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、Matlab求解積分問題探討一.相關(guān)函數(shù):%符號(hào)積分int(f,v)int(f,v,a,b)%數(shù)值積分trapz(x,y)?%梯形法沿列方向求函數(shù)Y關(guān)于自變量X的積分cumtrapz(x,y)?%梯形法沿列方向求函數(shù)Y關(guān)于自變量X的累計(jì)積分quad(fun,a,b,tol)?%采用遞推自適應(yīng)Simpson法計(jì)算積分quad1(fun,a,b,tol)?%采用遞推自適應(yīng)Lobatto法求數(shù)值積分?dbquad(fun,xmin,xmax,ymin,ymax,zmin,zmax,tol)?%二重(閉型)數(shù)值積分指令triplequad(fun,xmin,xmax,ymin
2、,ymax,zmin,zmax,tol)?%三重(閉型)數(shù)值積分指令二.示例:例1:計(jì)算f(t)=exp(-t^2)在[0,1]上的定積分本例演示:計(jì)算定積分常用方法>>?syms?xint(exp(-x^2),0,1)?ans?=?1/2*erf(1)*pi^(1/2)???%erf為誤差函數(shù)>>?vpa(int(exp(-x^2),0,1))?ans?=?.7468241328124270>>?d=0.001;x=0:d:1;d*trapz(exp(-x.^2))ans?=????0.7468>>?quad('exp(-x.^2)',0,1,1e-8)ans?=?
3、???0.7468例2:計(jì)算f(t)=1/log(t)在[0,x],01^-處為負(fù)無窮本例演示:用特殊函數(shù)表示的積分結(jié)果,如何用mfun指令(1)syms?t?xft=1/log(t);sx=int(ft,t,0,x)??sx?=-Ei(1,-log(x))??%完全橢圓函數(shù)(2)x=0.5:0.1:0.9sx_n=-mfun('Ei',1,-log(x))??????????????x?=????0.5000????0.6000????0.7000????0.8000????0.9000sx_n?=???-0.3
4、787???-0.5469???-0.7809???-1.1340???-1.7758??(3)%圖示被函數(shù)和積分函數(shù)clfezplot('1/log(t)',[0.1,0.9])????????????grid?onhold?onplot(x,sx_n,'LineWidth',3)????????????????Char1='1/ln(t)';Char2='{int_0^x}?1/ln(t)?dt';????????title([Char1,'???and????',Char2])????legend(Char1,Char2,'Location','SouthWe
5、st')??例3:計(jì)算f(t)=exp(-sin(t))在[0,4]上的定積分注意:本題被函數(shù)之原函數(shù)無"封閉解析表達(dá)式",符號(hào)計(jì)算無法解題!本例演示:符號(hào)計(jì)算有限性(1)符號(hào)計(jì)算解法syms?t?xft=exp(-sin(t))sx=int(ft,t,0,4)??ft?=exp(-sin(t))Warning:?Explicit?integral?could?not?be?found.>?In?sym.int?at?58sx?=int(exp(-sin(t)),t?=?0?..?4)??(2)數(shù)值計(jì)算解法dt=0.05;????????????????????%采樣
6、間隔????????????t=0:dt:4;???????????????????????%數(shù)值計(jì)算適合于有限區(qū)間上,取有限個(gè)采樣點(diǎn)???????????????Ft=exp(-sin(t));????????Sx=dt*cumtrapz(Ft);????????????%計(jì)算區(qū)間內(nèi)曲線下圖形面積,為小矩形面積累加得Sx(end)????????????????%所求定積分值????????????????????????????????%圖示plot(t,Ft,'*r','MarkerSize',4)hold?onplot(t,Sx,'.k','MarkerSiz
7、e',15)hold?offxlabel('x')legend('Ft','Sx')?>>ans?=?3.0632例4:繪制積分圖形,y=2/3*exp(-t/2)*cos(sqrt(3)/2*t);積分s(x)=int(y,t,0,x)于[0,4*pi]上syms?t?taoy=2/3*exp(-t/2)*cos(sqrt(3)/2*t);????s=subs(int(y,t,0,tao),tao,t);?????%獲得積分函數(shù)????????????subplot(2,1,1)???????????????????????????????????