您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > 对流方程各种格式代码matlab
对流方程——偏微分方程的数值解法用迎风格式解对流方程functionu=peYF(a,dt,n,minx,maxx,M)formatlong;h=(maxx-minx)/(n-1);ifa0forj=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:Mifa0fori=(k+1):n+Mu1(i)=-dt*a*(u0(i)-u0(i-1))/h+u0(i);endelsefori=1:n+M-ku1(i)=-dt*a*(u0(i+1)-u0(i))/h+u0(i);endendu0=u1;endifa0u=u1((M+1):M+n);elseu=u1(1:n);endformatlong;用拉克斯-弗里德里希斯格式解对流方程functionu=peHypbLax(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*a*(u0(i+1)-u0(i-1))/h/2+(u0(i+1)+u0(i-1))/2;endu0=u1;endu=u1((M+1):(M+n));formatshort;用拉克斯-温德洛夫格式解对流方程functionu=peLaxW(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*dt*a*a*(u0(i+1)-2*u0(i)+u0(i-1))/2/h/h-...dt*a*(u0(i+1)-u0(i-1))/h/2+u0(i);endu0=u1;endu=u1((M+1):(M+n));formatshort;用比姆-沃明格式解对流方程functionu=peBW(a,dt,n,minx,maxx,M)formatlong;h=(maxx-minx)/(n-1);forj=1:(n+2*M)u0(j)=IniU(minx+(j-2*M-1)*h);endu1=u0;fork=1:Mfori=2*k+1:n+2*Mu1(i)=u0(i)-dt*a*(u0(i)-u0(i-1))/h-a*dt*(1-a*dt/h)*...(u0(i)-2*u0(i-1)+u0(i-2))/2/h;endu0=u1;endu=u1((2*M+1):(2*M+n));formatshort;用Richtmyer多步格式解对流方程functionu=peRich(a,dt,n,minx,maxx,M)formatlong;h=(maxx-minx)/(n-1);forj=1:(n+4*M)u0(j)=IniU(minx+(j-2*M-1)*h);endu1=u0;fork=1:Mfori=2*k+1:n+4*M-2*ktmpU1=-dt*a*(u0(i+2)-u0(i))/h/4+(u0(i+2)+u0(i))/2;tmpU2=-dt*a*(u0(i)-u0(i-2))/h/4+(u0(i)+u0(i-2))/2;u1(i)=-dt*a*(tmpU1-tmpU2)/h/2+u0(i);endu0=u1;endu=u1((2*M+1):(2*M+n));formatshort;用拉克斯-温德洛夫多步格式解对流方程functionu=peMLW(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-ktmpU1=-dt*a*(u0(i+1)-u0(i))/h/2+(u0(i+1)+u0(i))/2;tmpU2=-dt*a*(u0(i)-u0(i-1))/h/2+(u0(i)+u0(i-1))/2;u1(i)=-dt*a*(tmpU1-tmpU2)/h+u0(i);endu0=u1;endu=u1((M+1):(M+n));formatshort;用MacCormack多步格式解对流方程functionu=peMC(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-ktmpU1=-dt*a*(u0(i+1)-u0(i))/h+u0(i);tmpU2=-dt*a*(u0(i)-u0(i-1))/h+u0(i-1);u1(i)=-dt*a*(tmpU1-tmpU2)/h/2+(u0(i)+tmpU1)/2;endu0=u1;endu=u1((M+1):(M+n));formatshort;用拉克斯-弗里德里希斯格式解二维对流方程的初值问题functionu=pe2LF(a,b,dt,nx,minx,maxx,ny,miny,maxy,M)%啦-佛formatlong;hx=(maxx-minx)/(nx-1);hy=(maxy-miny)/(ny-1);fori=1:nx+2*Mforj=1:(ny+2*M)u0(i,j)=Ini2U(minx+(i-M-1)*hx,miny+(j-M-1)*hy);endendu1=u0;fork=1:Mfori=k+1:nx+2*M-kforj=k+1:ny+2*M-ku1(i,j)=(u0(i+1,j)+u0(i-1,j)+u0(i,j+1)+u0(i,j-1))/4...-a*dt*(u0(i+1,j)-u0(i-1,j))/2/hx...-b*dt*(u0(i,j+1)-u0(i,j-1))/2/hy;endendu0=u1;endu=u1((M+1):(M+nx),(M+1):(M+ny));formatshort;用拉克斯-弗里德里希斯格式解二维对流方程的初值问题functionu=pe2FL(a,b,dt,nx,minx,maxx,ny,miny,maxy,M)%近似分裂formatlong;hx=(maxx-minx)/(nx-1);hy=(maxy-miny)/(ny-1);fori=1:nx+4*Mforj=1:(ny+4*M)u0(i,j)=Ini2U(minx+(i-2*M-1)*hx,miny+(j-2*M-1)*hy);endendu1=u0;fork=1:Mfori=2*k+1:nx+4*M-2*kforj=2*k-1:ny+4*M-2*k+2tmpU(i,j)=u0(i,j)-a*dt*(u0(i+1,j)-u0(i-1,j))/2/hx+...(a*dt/hx)^2*(u0(i+1,j)-2*u0(i,j)+u0(i-1,j))/2;endendfori=2*k+1:nx+4*M-2*kforj=2*k+1:nx+4*M-2*ku1(i,j)=tmpU(i,j)-b*dt*(tmpU(i,j+1)-tmpU(i,j-1))/2/hy+...(b*dt/hy)^2*(tmpU(i,j+1)-2*tmpU(i,j)+tmpU(i,j-1))/2;endendu0=u1;endu=u1((2*M+1):(2*M+nx),(2*M+1):(2*M+ny));formatshort;
本文标题:对流方程各种格式代码matlab
链接地址:https://www.777doc.com/doc-4639286 .html