Lax-Wendroff method for advection equation with periodic boundary condition

36 ビュー (過去 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 件のコメント
Moslem Uddin
Moslem Uddin 2022 年 3 月 14 日
I'm talking about order of accuracy.
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 Center および File ExchangeSpectral Measurements についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by