您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > 偏微分差分四种格式的matlab程序
偏微分差分四种格式的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((m+1):(m+n));plot(x,u,'r');axis([01-0.51.5]);holdony=1.*(x=0.5)+0.*(x0.5);plot(x,y,'c')title('Lax-Fridrichs')formatshort;functionux=U(x)formatlong;ifx=0ux=1;elseux=0;endu=LaxFridrichs(1,0.005,101,0,1,100)运行结果(2)迎风格式functionu=Yingfeng(a,dt,n,x1,x2,m)formatlong;h=(x2-x1)/(n-1);ifa0forj=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:mifa0fori=(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/100;u=u1((m+1):(m+n));plot(x,u,'r');axis([01-0.51.5]);holdony=1.*(x=0.5)+0.*(x0.5);plot(x,y,'c')formatshort;title('迎风格式')functionux=U(x)formatlong;ifx=0ux=1;elseux=0;endu=Yingfeng(1,0.005,101,0,1,100)运行结果(3)Lax-Wendroff格式functionu=LaxWendroff(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)=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]);holdony=1.*(x=0.5)+0.*(x0.5);plot(x,y,'c')title('Lax-Wendroff')formatshortfunctionux=U(x)formatlong;ifx=0ux=1;elseux=0;endu=LaxWendroff(1,0.005,101,0,1,100)运行结果(4)Beam-Warming格式functionu=BeamWarming(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+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.*(x0.5);plot(x,y,'c')title('Beam-Warming')formatshortfunctionux=U(x)formatlong;ifx=0ux=1;elseux=0;endu=BeamWarming(1,0.005,101,0,1,100)运行结果
本文标题:偏微分差分四种格式的matlab程序
链接地址:https://www.777doc.com/doc-7317030 .html