Parabolic pde using central finite difference method

I am trying to solve parabolic pde

$$\frac{\partial U}{\partial t} = \frac{\partial^2 U}{\partial x^2}$$

$U=x^2$ is the initial condition distribution, $0 \leq x \leq 1$ ($U$ is in dimensionless form.)

Discretizing the pde using central difference method and assuming $u$ as the exact solution,

$$\frac{u_{i,j+1}-u_{i,j-1}}{2k} = \frac{u_{i+1,j}-2u_{i,j}+u_{i-1,j}}{h^2}$$ $t=ik, x=jh$, where $i,j=0,1,2,3,...n$ Simplifying,

$$u_{i,j+1}=ru_{i-1,j}-2ru_{i,j}+ru_{i+1,j}+u_{i,j-1}$$ Where, $r=2k/h^2$

I have question in terms $u_{i,j-1}$ and $u_{i+1,j}$

• When $t=0$, what should be value of $u_{i,j-1}$? How valid is it to assume it as zero?
• What happens at $x=1$? What should be value of $u_{i+1,j}$ as this quantity will lie outside the domain.

Can someone comment on these questions?

• You need some boundary conditions associated with $x=0,1$ – parsiad Sep 26 '17 at 0:48
• and also, this a very bad method for the heat equation. Your finite difference equation is reversible, the PDE is not. This will lead to instability. – Philip Roe Sep 26 '17 at 0:52
• Use Crank-Nicolson instead: en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method – parsiad Sep 26 '17 at 0:53

1. You cannot make assumptions for $u_{i,j-1}$ at t=0. Use a forward difference in time not a central difference. i.e., represent the time derivative by $$\frac{u_{i,j+1}-u_{i,j}}{k}$$. It has the added benefit that the scheme will be stable (for small enough values of $\frac{k}{h^2}$). If you want to take largest steps in time without losing stability, use an implicit scheme like the Crank Nicholson that parsiad mentions.
2. If you have boundary conditions (either $U$ or $U_x$ specified at x=0 and x=1 for all 0 < t < T ), then you only solve the function values at $j=1,...,n-1$. Since $j=0$ and $j=n$ are not evaluated, no problem with the central spatial difference.
• Thanks for your answer. I do not understand why we can't assume $u_{i,j-1}=0$ at $t=0$. Is that because we do not have this information? Or is there some other reason? – ccdq23 Oct 1 '17 at 0:43
• That's right. You can intuitively see that there is problem if you look at some point (say x=0.5). Then at t=0, we're saying U has a specific value $(0.5^2)$, but just before that, at $t=-\Delta t$, we are saying it was zero. Artificially induced "badness"! – Mathemagical Oct 1 '17 at 0:49