Numerical Analysis Home

Parabolic PDE: Heat Equation

    


The one-dimensional heat equation is \[\begin{align*} &\frac{\partial u}{\partial t}(x,t)=\alpha^2\frac{\partial^2 u}{\partial x^2}(x,t),\; 0 < x < l,\; t >0,\\ &u(0,t)=u(l,t)=0,\; t > 0,\; \text{ and } u(x,0)=f(x),\; 0 < x < l. \end{align*}\] First we make a grid of the domain of \((x,t)\) with step size \(h\) and \(k\) respectively: \[\begin{align*} &x_i=ih,\; i=0,1,\ldots,m.\;\; (h=(l-0)/m)\\ &t_j=jk,\; j=0,1,\ldots \end{align*}\]

Now we approximate \(u(x_i,t_j)\) by \(u_{i,j}\) using the Difference Method:
By the FDF in variable \(t\), we get \[\frac{\partial u}{\partial t}(x_i,t_j)=\frac{u(x_i,t_j+k)-u(x_i,t_j)}{k}-O(k) \approx \frac{u_{i,j+1}-u_{i,j}}{k}.\] Similarly by the CDF in variable \(x\), we get \[\frac{\partial^2 u}{\partial x^2}(x_i,t_j)=\frac{u(x_i+h,t_j)-2u(x_i,t_j)+u(x_i-h,t_j)}{h^2}-O(h^2) \approx \frac{u_{i+1,j}-2u_{i,j}+u_{i-1,j}}{h^2}.\] Plugging these \(u_t(x_i,t_j)\) and \(u_{xx}(x_i,t_j)\) into the heat equation, we get \[\begin{align*} &\frac{u_{i,j+1}-u_{i,j}}{k}=\alpha^2 \frac{u_{i+1,j}-2u_{i,j}+u_{i-1,j}}{h^2}\\ \implies & u_{i,j+1}=\lambda u_{i+1,j}+(1-2\lambda)u_{i,j}+\lambda u_{i-1,j}\; (\lambda=k\alpha^2/h^2)\\ \implies & u_{i,j+1}=(1-2\lambda)u_{i,j}+\lambda(u_{i+1,j}+ u_{i-1,j}),\;i=1,\ldots,m-1,\;j=0,1,2,\ldots \end{align*}\] By the initial condition \(u(x,0)=f(x)\), we have \[u_{0,0}=f(x_0),u_{1,0}=f(x_1),\ldots,u_{m,0}=f(x_m).\] Using \(u_{0,0},u_{1,0},\ldots,u_{m,0}\), we can find \(u_{0,1},u_{1,1},\ldots,u_{m,1}\) and so on at different values of \(t_j\).

Note \[ \left[ \begin{array}{ccccc} (1-2\lambda) & \lambda & 0&\dots &0\\ \lambda & (1-2\lambda)&\ddots &\ddots &\vdots \\ 0 & \ddots &\ddots &\ddots &0\\ \vdots & \ddots &\ddots &\ddots &\lambda\\ 0 & \dots &0 & \lambda & (1-2\lambda) \end{array} \right] \left[ \begin{array}{l} u_{1,j}\\u_{2,j}\\ \vdots\\ \vdots\\u_{m-1,j} \end{array} \right]= \left[ \begin{array}{l} u_{1,j+1}\\u_{2,j+1}\\ \vdots\\ \vdots\\u_{m-1,j+1} \end{array} \right]\] If we write \(\overrightarrow{u}^{(j)}=[u_{1,j},\ldots,u_{m-1,j}]^T\), then it becomes \[\boxed{\begin{align*} &\overrightarrow{u}^{(j+1)}=A\overrightarrow{u}^{(j)},\; j=0,1,2,\ldots\\ &\overrightarrow{u}^{(0)}=[f(x_1),\ldots,f(x_{m-1})]^T. \end{align*}}\]

The order of error is \(O(k+h^2)\). It can be shown that the difference method is conditionally stable if \(\rho(A)<1\) which implies (steps skipped) if \[\lambda=\frac{k\alpha^2}{h^2}\leq \frac{1}{2}.\]


Example. Approximate the solution of the following heat equation at \(t=0.4\) by the difference method using \(h=0.25\) and \(k=0.2\). \[\begin{align*} &\frac{\partial u}{\partial t}(x,t)=\frac{1}{16}\frac{\partial^2 u}{\partial x^2}(x,t),\; 0 < x < 1,\; t\geq 0,\\ &u(0,t)=u(1,t)=0,\; t > 0,\; \text{ and } u(x,0)=\sin(2\pi x),\; 0 < x < 1. \end{align*}\] Compare the result at \(t=0.4\) using the exact solution \(u(x,t)=e^{-\pi^2t/4}\sin(2\pi x)\).

Solution. \(h=0.25\), \(k=0.2\), \(\alpha^2=1/16\). So \(\lambda=k\alpha^2/h^2=1/5\) and \(m=(l-0)/h=4\). \[x_0=0,x_1=0.25,x_2=0.5,x_3=0.75,x_4=1\] Here \(f(x)=\sin(2\pi x)\). So \(u_{0,0}=f(x_0)=0,u_{1,0}=f(x_1)=1,u_{2,0}=f(x_2)=0,\) \(u_{3,0}=f(x_3)=-1,u_{4,0}=f(x_4)=0.\) For \(\overrightarrow{u}^{(j)}=[u_{1,j},u_{2,j},u_{3,j}]^T\), \[\begin{align*} \overrightarrow{u}^{(j+1)}=A\overrightarrow{u}^{(j)}, \text{ i.e., } & \left[ \begin{array}{l} u_{1,j+1}\\u_{2,j+1}\\u_{3,j+1}\end{array} \right]= \left[ \begin{array}{ccc} 0.6 &0.2 &0\\ 0.2 &0.6 &0.2\\ 0 &0.2 &0.6 \end{array} \right] \left[ \begin{array}{l} u_{1,j}\\u_{2,j}\\u_{3,j}\end{array} \right],\; j=0,1,2,\ldots\\ \overrightarrow{u}^{(0)}=[f(x_1),f(x_2),f(x_3)]^T, \text{ i.e., } & \left[ \begin{array}{l} u_{1,0}\\u_{2,0}\\u_{3,0} \end{array} \right]=\left[ \begin{array}{r} 1\\0\\-1\end{array} \right]. \end{align*}\] \[\begin{array}{|c|r|r|r|r|r|} \hline i & x_i & u_{i,0} &u_{i,1} &u_{i,2} &u(x_i,0.4)\\ \hline 0 & 0.00 & 0 &0.00 &0.00 &0.00\\ \hline 1 & 0.25 & 1 &0.60 &0.36 &0.37\\ \hline 2 & 0.50 & 0 &0.00 &0.00 &0.00\\ \hline 3 & 0.75 & -1 &-0.60 &-0.36 &-0.37\\ \hline 4 & 1.00 & 0 &0.00 &0.00 &0.00\\ \hline \end{array} \]


Last edited