Lax-Wendroff method for advection equation with periodic boundary condition
36 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Alan Stevens
am 13 Mär. 2022
If you make dt=0.1*h/a; instead of dt=0.95*h/a; your max error reduces to 0.0355.
2 Kommentare
Torsten
am 14 Mär. 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" ?
Siehe auch
Kategorien
Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!