function linear_convection_example
T = 50;
L = 2*pi;
U = -0.2;
N_y = 100;
y = linspace(0,L,N_y);
dx = L/N_y;
u = sin(y)’;
u(1) = U;
C = zeros(100,100);
for i = 1:N_y
if i==1 %|| i==N_y
C(i,i) = 1;
C(i,end) = -1;
else
C(i,i-1:i) = [-1,1];
end
end
dt = 0.01;
N_t = ceil(T/dt);
CFL = U*dt/dx;
figure(‘Visible’,”on”)
Solution = plot(y, u);
xlim([0,L]);
ylim([-1,1]);
grid on;
xlabel(‘x’);
ylabel(‘y’);
colormap(cool);
drawnow;
for n = 1:N_t
u1 = u(1);
u = u + (U*dt/dx)*C*u;
%u(1) = u1
%u(end) = 0;
if(~mod(n, 2))
set(Solution, ‘YData’, u);
drawnow;
end
end
end