function wave(N,steps) %wave(N,steps) solves the wave equation u_t + u_x = 0 % with N+1 gridpoints for 0 <= x <= 1 % to time t = steps*h, h = 1/N (CFL factor = 1) % For the ICs, N >= 20 should be an integer multiple of 10 % Uses upwind method & periodic BCs h = 1/N; dt = h; % CFL factor = 1 u = zeros(N+1,1); % set u to be an N+1 dimensional column vector j = 0:N/10; u(j+1) = sin(10*j*pi/N); % ICs x = linspace(0,1,N+1); for n = 1:steps % timestep loop upwind = [u(N+1);u(1:N)]; % with periodic BC u = u - dt*(u-upwind)/h; % upwind method end plot(x,u,'r-') xlabel('x','FontSize',16) ylabel('u','FontSize',16) end