Lax-Wendroff method for advection equation with periodic boundary condition

37 vues (au cours des 30 derniers jours)
Moslem Uddin
Moslem Uddin le 13 Mar 2022
Commenté : Torsten le 14 Mar 2022
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.

Réponses (1)

Alan Stevens
Alan Stevens le 13 Mar 2022
If you make dt=0.1*h/a; instead of dt=0.95*h/a; your max error reduces to 0.0355.
  2 commentaires
Moslem Uddin
Moslem Uddin le 14 Mar 2022
I'm talking about order of accuracy.
Torsten
Torsten le 14 Mar 2022
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" ?

Connectez-vous pour commenter.

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by