Contents
% This script file computes for the transport equation u_t+cu_x=0 the % followings: solution, characteristics close all; clear all; speed=1;%input('Input the propagation speed ')
SECTION TITLE
Define the initial function
f_initial=@(x)exp(-2*(x-1).^2);
% Calculate and plot the solution in 3D x=0:.1:8; t=0:.1:5; [X,Y]=meshgrid(x,t); solution_u=@(x,t,c)f_initial(x-c*t); Z=solution_u(X,Y,speed); %mesh(X,Y,Z); %mesh plot surf(X,Y,Z); %surface plot xlabel('x','FontSize',14); ylabel('t','FontSize',14); zlabel('u','FontSize',14); title('Solution u(x,t) of the transport equation with constant c')

%Instead of a 3D plot it makes a 2D plot of the colors used in surf figure pcolor(X,Y,Z); title('2-D plot of the contours of the solution surface') %figure %contour(X,Y,Y,5)

% Calculate and plot a few characteristic curves (lines) t=0:0.1:5; x0=-9:.5:8; m=size(x0,2); char_curve=@(c,x0,t)x0+c*t; figure for i=1:m plot(char_curve(speed,x0(i),t),t) hold on end; hold off axis([0 8 0 5]); xlabel('x axis','FontSize',14); ylabel('t axis','FontSize',14); title('Characteristics')
