資源描述:
《偏微分各差分格式matlab編程》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、(1)迎風(fēng)格式functionu=peHypbYF(a,dt,n,minx,maxx,M)formatlong;h=(maxx-minx)/(n-1);ifa>0forj=1:(n+M)u0(j)=IniU(minx+(j-M-1)*h);endelseforj=1:(n+M)u0(j)=IniU(minx+(j-1)*h);endendu1=u0;fork=1:Mifa>0fori=(k+1):n+Mu1(i)=-(dt/h)*a*(u0(i)-u0(i-1))+u0(i);endelsefori=1:n+M-
2、ku1(i)=-(dt/h)*a*(u0(i+1)-u0(i))+u0(i);endendu0=u1;endx=0.01:0.01:n/100;u=u1((M+1):(M+n));plot(x,u,'r');axis([01-0.51.5]);holdony=1.*(x<=0.5)+0.*(x>0.5);plot(x,y,'g')title('ó·???ê?')formatshort;運行結(jié)果>>u=peHypbYF(1,0.005,101,0,1,100)(2)Lax-Fridrichs格式functionu=
3、LaxFridrichs(a,dt,n,minx,maxx,M)formatlong;h=(maxx-minx)/(n-1);forj=1:(n+2*M)u0(j)=IniU(minx+(j-M-1)*h);endu1=u0;fork=1:Mfori=k+1:n+2*M-ku1(i)=-(dt/h)*a*(u0(i+1)-u0(i-1))/2+(u0(i+1)+u0(i-1))/2;endu0=u1;endx=0.01:0.01:n/100;u=u1((M+1):(M+n));plot(x,u,'r');axis
4、([01-0.51.5]);holdony=1.*(x<=0.5)+0.*(x>0.5);plot(x,y,'g')title('Lax-Fridrichs??ê?')formatshort;運行結(jié)果>>u=LaxFridrichs(1,0.005,101,0,1,100)(3)Lax-Wendroff格式functionu=LaxWendroff(a,dt,n,minx,maxx,M)formatlong;h=(maxx-minx)/(n-1);forj=1:(n+2*M)u0(j)=IniU(minx+(j-
5、M-1)*h);endu1=u0;fork=1:Mfori=k+1:n+2*M-ku1(i)=(dt/h)^2*a*a*(u0(i+1)-2*u0(i)+u0(i-1))/2-...(dt/h)*a*(u0(i+1)-u0(i-1))/2+u0(i);endu0=u1;endx=0.01:0.01:n/100;u=u1((M+1):(M+n));plot(x,u,'r');axis([01-0.51.5]);holdony=1.*(x<=0.5)+0.*(x>0.5);plot(x,y,'g')title('La
6、x-Wendroff??ê?')formatshort運行結(jié)果>>u=LaxWendroff(1,0.005,101,0,1,100)(4)Beam-Warming格式functionu=BeamWarming(a,dt,n,minx,maxx,M)formatlong;h=(maxx-minx)/(n-1);forj=1:(n+2*M)u0(j)=IniU(minx+(j-M-1)*h);endu1=u0;fork=1:Mfori=k+2:n+2*M-ku1(i)=-a*(dt/h)*(u0(i)-u0(i-1
7、))-a*(dt/h)*(1-a*(dt/h))*(u0(i)-2*u0(i-1)+u0(i-2))/2+u0(i);endu0=u1;endx=0.01:0.01:n/100;u=u1((M+1):(M+n));plot(x,u,'r');axis([01-0.51.5]);holdony=1.*(x<=0.5)+0.*(x>0.5);plot(x,y,'g')title('Beam-Warming??ê?')formatshort;運行結(jié)果>>u=BeamWarming(1,0.005,101,0,1,100
8、)