Additional literature: This class introduces the basic ideas of Partial Differential Equations where we skip some details and proofs. Here are some graduate level books with more mathematical theory and complete proofs:

Download heat_pwlin.m. This computes the solution of the heat equation on R if the initial function u0(x) is piecewise linear (and constant for
x≤z1, x≥zN).
Example: u0(-1)=0, u0(0)=1, u0(1)=0. To find the solution for t=0,.02,...,1:

heat_pwlin([-1 0 1],[0 1 0],0:.02:1);

Feb. 15: We looked for the solution of Ut=Uxx with initial condition U(x,0)=0 for x<0, U(x,0)=1 for x>0. Let g(x):=U(x,1) denote
the solution at time t=1. Because of dilation invariance we have

U(x,t) = g(t-1/2x)

We found that

g(x) = ½·π-1/2·∫0xexp(-p2/4)dp + ½
= ½·erf(x/2) + ½

The "error function" erf(x) is defined as π-1/2·∫0xexp(-p2)dp, this function is available in Matlab and many other
programming languages. In Matlab we can plot the solution U(x,t) for x∈[-5,5],
t∈[0,2] as follows:

For traffic flow the function u(x,t) represents the density where the maximal density is 1. We then have that speed = 1-u and flux F(u) = u·(1-u). Then the PDE is ut + F(u)x = 0. Note that
c(u)=1-2u will be negative for large densities, therefore characteristics have negative slope and density values will propagate to the left. Even if initially the density is a smooth function, from some time t* on there will be a discontinuity in the density ("shock").
Here is a practical demonstration
(in real life there are small random perturbations which can create a traffic jam out of nowhere if the initial density is high enough).

Download the m-files colorcurves.m and
quasilin.m. Put these files in the same directory as your other m-files. How to use quasilin: Consider the initial value problem from class

ut - x·ux = u, u(x,0) = exp(-x2).

Here c(x,t,u)=-x, f(x,t,u)=u, u0(x)=exp(-x2).
We use for x0 the values -3,-2.9,...,2.9,3. We want to find the solution u(x,t) for 0≤t≤1 so we use t-values 0,.1,...,.9,1: