|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
按照附件图片中的方法想用对流方程测试下其阶数,u_t+u_x=0, 周期边界,初值取 sin(pi*x), matlab 程序如下, 但是跑一会数值解的波峰和波谷就会变平掉,精度也的达不到2阶,请教为什么会有这个结果,程序里面什么地方有问题呢? 万分感谢
- clc, clear
- f = inline('u');
- N = 200; dx = 2/N; x = 0:dx:2-dx; x = x';
- dt = 0.5*dx; tend = 50; T = tend/dt;
- u = sin(pi*x); u1 = zeros(N,1);
- for j = 1:T
- t = j*dt;
- um1 = circshift(u,1); um2 = circshift(um1,1); up1 = circshift(u,-1);
- ubar = (f(u)-f(um1))./(u-um1); lam = dt/dx*ubar;
-
- Id1 = find(ubar>0); Id2 = find(ubar<=0);
-
- if ~isempty(Id1)
- r1 = (um1(Id1)-um2(Id1))./(u(Id1)-um1(Id1));
- phi1 = superbee(r1); Phi1 = circshift(phi1,-1);
-
- u1(Id1) = u(Id1)-dt/dx*(f(u(Id1))-f(um1(Id1)))-...
- 1/2*lam(Id1).*(1-lam(Id1)).*(Phi1.*(up1(Id1)-u(Id1))-phi1.*(u(Id1)-um1(Id1)));
- end
-
- if ~isempty(Id2)
- r2 = (up1(Id2)-u(Id2))./(u(Id2)-um1(Id2));
- phi2 = superbee(r2); Phi2 = circshift(phi2,-1);
-
- u1(Id2) = u(Id2)-dt/dx*(f(up1(Id2))-f(u(Id2)))-...
- 1/2*lam(Id2).*(1+lam(Id2)).*(Phi2.*(up1(Id2)-u(Id2))-phi2.*(u(Id2)-um1(Id2)));
- end
-
- uex = sin(pi*(x-t));
- plot(x,u1,x,uex,'r--'); h = gca; set(h,'xlim',[0,2],'Ylim',[-1.5,1.5]);
- drawnow
-
- u = u1;
- fprintf('Computing times = %d Total times = %d\n',j,T)
-
- end
复制代码 |
-
二阶TVD格式构造
|