Here we are to solve
\[u_{t} = u_{xx}\]
subject to the initial value condition
\begin{eqnarray*}
u(x,0) = \sin{x} & \textrm{for} & x \in [0,\pi]
\end{eqnarray*}
and the boundary conditions
\begin{eqnarray*}
u(0,t) = u(\pi,t) = 0 & \textrm{for all} & t \geq 0
\end{eqnarray*}
Using the Douglas formula and the Crank-Nicolson method.  We accomplished this using Python along with the NumArray library to solve the linear systems (code available upon request).  We have prepared a table that lists the number of time steps $n$, the theoretical solution (given by $u(x,t) = e^{-t} \sin{x}$), the value for each method followed by the error at the midpoint.
\input{table_p09}
We need to mention here that getting the values at the midpoint was a little tricky.  When we discritize in $x$, we get a list of function values for each of these points.  For this problem, this means a function value for $x_{m} = 0,1,2,\ldots,20$.  Since we are given the values along the boundary, we can throw out the conditions on the end, giving us values $x_{m} = 1,2,\ldots,19$.  When we calculate the true solution in the middle, we set $x = 10h$, since $10$ is the middle value.  However, when we look at the middle value in our array, this corresponds to position $9$.  This gets a little tricky at times.  It is good to bear in mind that we should really look for the maximum error on this interval and that looking just at the middle value is laziness on our part.

It is also interesting to note is how well the Douglas formula performs.  By applying methods based solely on the PDE, we gain an increase in accuracy on the order of $10^{-7}$.  This is a significant increase above the Crank Nicolson method.  Since both methods are equally difficult/easy (depending on your point of view) to implement, there is no reason to use the Crank Nicolson method.
