필터 지우기
필터 지우기

Lax-Wendroff method for advection equation with periodic boundary condition

조회 수: 12 (최근 30일)
Moslem Uddin
Moslem Uddin 2022년 3월 13일
댓글: Torsten 2022년 3월 14일
I'm trying to solve advection equation in with and periodic boundary conditions . My approach is as follow:
clc,clear
xmin=0;
xmax=1;
m=400;%space
t=0;
h=1/(m+1);
n=10/(0.95*h);%time steps
a=1;
dt=0.95*h/a;
x=xmin:h:xmax;
a1=a*dt/(h);
% ic
u0=cos(2*pi*x)+.2*cos(10*pi*x);
% plot(x,u0,'k*')
% hold on
u=u0;
un=u0;
% v = VideoWriter('newfile2.avi');
% open(v)
for j=1:n%time
%bc
% u(1)=u(m+1);
for i=2:m+1%space
un(i)=u(i)-(a1/2)*(u(i+1)-u(i-1))+0.5*(a1)^2*(u(i+1)-2*u(i)+u(i-1));
end
un(1)=un(m+1);
un(m+2)=un(2);
u=un;
t=t+dt;
%exact
y_e=(cos(2*pi*(x-t))+.2*cos(10*pi*(x-t)));
plot(x,y_e)
hold on
plot(x,u,'bo-','MarkerFaceColor','r')
hold off
title(sprintf('time=%1.3f',t))
shg
pause(dt)
% frame = getframe(gcf);
% writeVideo(v,frame);
end
% close(v)
error=abs(max(y_e-un))
The code is running well. However, I'm not getting desired order of accuracy. Your help will be appreciated.

답변 (1개)

Alan Stevens
Alan Stevens 2022년 3월 13일
If you make dt=0.1*h/a; instead of dt=0.95*h/a; your max error reduces to 0.0355.
  댓글 수: 2
Torsten
Torsten 2022년 3월 14일
We can't see where you varied the spatial and/or temporal resolution and calculated the convergence order.
Or what is your definition of "order of accuracy" ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by