資源描述:
《偏微分差分四種格式的matlab程序.doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、偏微分差分四種格式的matlab程序(1)Lax-Fridrichs格式functionu=LaxFridrichs(a,dt,n,x1,x2,m)formatlong;h=(x2-x1)/(n-1);forj=1:(n+2*m)u0(j)=U(x1+(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
2、((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,'c')title('Lax-Fridrichs')formatshort;functionux=U(x)formatlong;ifx<=0ux=1;elseux=0;end>>u=LaxFridrichs(1,0.005,101,0,1,100)運(yùn)行結(jié)果(2)迎風(fēng)格式functionu=Yingfeng(a,dt,n,x1,x2,m)forma
3、tlong;h=(x2-x1)/(n-1);ifa>0forj=1:(n+m)u0(j)=U(x1+(j-m-1)*h);endelseforj=1:(n+m)u0(j)=U(x1+(j-1)*h);endendu1=u0;fork=1:mifa>0fori=(k+1):n+mu1(i)=u0(i)-(dt/h)*a*(u0(i)-u0(i-1));endelsefori=1:n+m-ku1(i)=u0(i)-(dt/h)*a*(u0(i+1)-u0(i));endendu0=u1;endx=0.01:0.01:n
4、/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,'c')formatshort;title('迎風(fēng)格式')functionux=U(x)formatlong;ifx<=0ux=1;elseux=0;end>>u=Yingfeng(1,0.005,101,0,1,100)運(yùn)行結(jié)果(3)Lax-Wendroff格式functionu=LaxWendroff(a,dt,n,x1,x
5、2,m)formatlong;h=(x2-x1)/(n-1);forj=1:(n+2*m)u0(j)=U(x1+(j-m-1)*h);endu1=u0;fork=1:mfori=k+1:n+2*m-ku1(i)=u0(i)-(dt/h)*a*(u0(i+1)-u0(i-1))/2+(dt/h)^2*a*a*(u0(i+1)-2*u0(i)+u0(i-1))/2;endu0=u1;endx=0.01:0.01:n/100;u=u1((m+1):(m+n));plot(x,u,'r');axis([01-0.51.5]
6、);holdony=1.*(x<=0.5)+0.*(x>0.5);plot(x,y,'c')title('Lax-Wendroff')formatshortfunctionux=U(x)formatlong;ifx<=0ux=1;elseux=0;end>>u=LaxWendroff(1,0.005,101,0,1,100)運(yùn)行結(jié)果(4)Beam-Warming格式functionu=BeamWarming(a,dt,n,x1,x2,m)formatlong;h=(x2-x1)/(n-1);forj=1:(n+2*
7、m)u0(j)=U(x1+(j-m-1)*h);endu1=u0;fork=1:mfori=k+2:n+2*m-ku1(i)=u0(i)-a*(dt/h)*(u0(i)-u0(i-1))-a*(dt/h)*(1-a*(dt/h))*(u0(i)-2*u0(i-1)+u0(i-2))/2;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(
8、x,y,'c')title('Beam-Warming')formatshortfunctionux=U(x)formatlong;ifx<=0ux=1;elseux=0;end>>u=BeamWarming(1,0.005,101,0,1,100)運(yùn)行結(jié)果