Numerical solutions to the transport equation

Hi everyone,

I have an assignment from my professor for 3 weeks from now. It is about solving the transport equation, u_t+c*u_x=0, using numerical schemes in matlab. Unfortunately, I have never used matlab before and the lecturer has only gone over very basic techniques in the lecture. Is there anyone out there who has done this before and could offer me some advice as to how I would go about doing this? Thanks

Re: Numerical solutions to the transport equation

ok, a more simple question, can anyone out there make a 3d plot/mesh of u,x and t from this code? :

clear all

clc

clf

% First set the initial parameters.

p=0; % start of computational domain

q=100; % end of computational domain

v=1; % water speed

N=101; % number of grid points

dx=(q-p)/(N-1); % spatial step size

x = p: dx : q; % vector of grid points

u0=zeros(1,N); % vector of initial u values filled with zeros

for i=1:N

u0(i)=finitial(x(i)-0); % initial conditions

end

%

dt=0.3; % fixed time step

ntimesteps=200; % number of time steps

r =v*dt/dx;

%

u=zeros(1,N); % define correct sized numerical solution array

exact=zeros(1,N); % define correct sized exact solution array

%

% Begin the time marching algorithm

%

for n=1:ntimesteps

t=n*dt; % current time for outputted solution

for i=1:N

exact(i)=finitial(x(i)-v*t); % exact solution at time t

end

u0=[u0(1) u0]; % insert ghost value (appropriate to numerial scheme)

for i=2:N+1

u(i)=u0(i)-r*(u0(i)-u0(i-1)); % backward difference algorithm

end

plot(x,u(2:N+1),'r',x,exact,'k') % plot (omitting ghost values) of numerical and exact solutions

xlabel('x')

ylabel('concentration u')

title('comparison of solutions to du/dt + v du/dx = 0, + numerical (FOU), o analytical')

pause(0.03) % pause in seconds between plots

u0=u(2:N+1); % copy solution to initial conditions for next iteration

u=[]; % empty the solution vector (actually it will be overwritten)

end