

Using EXCEL Spreadsheets to Solve a 1D Heat Equation  
The goal of this tutorial is to create an EXCEL spreadsheet that calculates the numerical solution to the following initialboundary value problem for the onedimensional heat equation:
The basic idea of the numerical approach to solving differential equations is to replace the derivatives in the heat equation by difference quotients and consider the relationships between u at (x,t) and its neighbours a distance Δx apart and at a time Δt later. In particular, in this tutorial the following expressions will be used:
Hence, given the values of u at three adjacent points xΔx, x, and x+Δx at a time t, one can calculate an approximated value of u at x at a later time t+Δt.
Using EXCEL spreadsheets allows you to perform these calculations repeatedly and effortlessly. The following are the necessary steps to set up a spreadsheet to calculate the solution to the initialboundary value problem shown above.
The first step is to tabulate the sample points in the spatial interval. Subdivide the interval [0, 1] into N+1 equallyspaced sample points a distance Δx apart.
In a blank EXCEL spreadsheet, enter the sample points along a row, as shown below. For this tutorial, let Δx = 0.05 and N = 19. Note that the value of Δx is shown in cell C2.
Each sample point is calculated as
for n = 1, ... N and x_{0} = 0.
For example, in the spreadsheet below the first sample point in the interval is x_{1} = x_{0} + 0.05. The value of x_{1} is shown in cell E5: it is computed by addying the fixed space increment (cell C2) to the value contained in the cell to the immediate left of E5 (cell D5). The expression in the formula box in the image below shows the specific EXCEL formula used to compute the value in cell E5.
The second step is to tabulate the time interval. Subdivide the interval [0,T] into M+1 equal time levels Δt long.
Enter the time levels in a column in the EXCEL spreadsheet, as shown below. For this tutorial, let Δt = 0.004 and M = 20. Note that the value of Δt is shown in cell F2.
Each time level is calculated as
for k = 1, ... M and t_{0} = 0.
For example, in the spreadsheet below the second time level is t_{2}=t_{1} + 0.004. The value of t_{2} is shown in cell B9: it is computed by adding the fixed time increment (cell F2) to the value contained in the cell immediately above B9 (cell B8). The expression in the formula box in the image below shows the specific EXCEL formula used to compute the value in cell B9.
The next step is to assign the initial condition u(x,0) = f(x). Note that the specific form of f(x) depends on the characteristic of the problem under consideration. For this tutorial, choose
f(x) = 2x for 0 < x < 0.5 and f(x) = 22x for 0.5 < x < 1.
For clarity, in the spreadsheet below spacetime points have been highlighted in blue and the corresponding values of the solution at t = 0 in green. In other words, the values of the initial condition are shown in row 7, in cells D7 through X7. For example, the value of u(0.1, 0), that is, the value of u at x_{2} at t_{0}, is shown in cell F7.
The initialboundary value problem discussed in this tutorial has two boundary conditions:
u(0, t) = 0 and u(1, t) = 0.
In the spreadsheet shown below, column D, from cells D7 through D27, contains the values corresponding to the first boundary condition u(0, t) = 0, that is, it shows the constant value of u at x_{0}. Column X, from cells X7 through X27, instead, contains the second boundary condition u(1, t) = 0, that is, it shows the constant value of u at x_{N}. Note that at t_{0}, u(1, 0) = 0 (cell X7) in agreement with the initial condition.
for n = 1, 2, ... N. Thus, u_{n}^{k+1}, the approximated value of u at point x_{n} at a time t_{k+1}, can be calculated given the values of u at three adjacent points, x_{n1}, x_{n}, x_{n+1}, at a time t_{k}.
For example, the value of u at x_{1} at time t_{1} can be approximated as u(x_{1}, t_{1}) ~ u_{1}^{1}, and calculated using the expression above with n = 1 and k = 0,
where
Hence, given the value of u at x_{0}, x_{1}, x_{2} at time t_{0}, one can find an approximated value of u at x_{1} one time step later. The spreadsheet below shows how to perform this calculation:
One could perform a similar calculation to find u_{2}^{1}, the (approximated) value of u at a sample point a distance Δx to the right of x_{1} and at the same time level as u_{1}^{1}. The result of the computation would be stored in the same row (or time level) as u_{1}^{1} (row 8), but one column to the right (column F), to be consistent with the way sample spacetime points are tabulated in the spreadsheet. Furthermore, the computation of u_{2}^{1} would involve the values of u at x_{1}, x_{2}, and x_{3} at time t_{0}, which are stored in cells E7, F7, and G7. In other words, the computation of u_{2}^{1} would involve information in three cells located to the immediate right with respect to the cells used to compute u_{1}^{1}. Therefore, instead of typing a new formula for u_{2}^{1} in cell F8, one could simply Copy and Paste the formula from cell E8 into cell F8, EXCEL will then automatically update the formula. In fact, when a formula is copied from one cell to another, EXCEL does not create an exact copy of the formula, instead it changes cell addresses relative to the row and column they are moved to. When the formula from cell E8 is pasted one cell to the right (into F8), all column labels in the formula, with the exception of cell O2, will be shifted to the right, and the correct values of u will be accessed. The cell address for O2 will not change because the column and row labels are preceded by the "$" sign (this is called "absolute referencing" of cells), allowing for the constant value of K to be read always from cell O2.
The same method can be used to calculate values of u at later times. Instead of typing a new formula in subsequent rows, simply copy and paste the formula from the cell corresponding to the previous time level, i.e. the cell in the row above.
Keep in mind that in order to compute the time evolution of u at a particular point in the space interval, its earlier value at that point and at adjacent points must be known. Therefore, before calculating how u changes with time at a given point, it is convenient to find earlier values of u at all points in the spatial interval. In other words, when using the spreadsheet to calculate u, first fill in all cells in one row, and then move to the row below, so that the necessary values of u are always available. The EditFillFill Right and EditFillFill Down features will allow you to fill in all cells and calculate the solution quickly.
Your plot may look like the image below. By increasing M and implementing the computation on more time level (i.e., by filling more rows in the spreadsheet), you can investigate the evolution of u at even later time.
Suppose the boundary conditions to the initialboundary value problem discussed at the beginning of this tutorial are changed to
Unlike the previous case, in which the boundary conditions provided the value of the solution on both boundaries of the domain, now the value of the solution is known only at x = 0. Thus, u(1, t) must be calculated using the same difference approximation for the heat equation used in Step 5, but now n = N, that is,
By doing so, one finds that the value of u at x_{N} depends on the value of u at x_{N+1}. Recall that x_{N+1} = x_{N} + Δx. Since x_{N} = 1, then, x_{N+1} is outside the domain and must be defined. In practical terms, this means adding a column in the spreadsheet used to calculate the solution. Alternatively, one could seek a new expression for u_{N}^{k} that does not depend on the value of u at x_{N+1}, avoiding therefore the additional column in the spreadsheet. In both cases, it will be essential to use the information provided by the derivative boundary condition, as described below.
Consider a central difference approximation of the derivative boundary condition,
It follows thatSince x_{N+1} = x_{N} + Δx and x_{N1} = x_{N}  Δx, it follows that u_{N+1}^{k} = u_{N1}^{k}. This information can be used to calculate u_{N}^{k+1} in two ways:
