Notation:
- $w$ denotes approximate solution of $u$
- $f(x)$ denotes initial condition.
- $l(t)$ and $r(t)$ are the boundary conditions.
Right now I'm trying to write some code to solve a simple heat equation: $$u_t = D\cdot u_{xx},\,\ 0\leq x\leq M, \,t\geq0$$ The method I'm using is a Forward Difference Method to step forward in time. For the very first time step, I have to use the extremes, $w_{0,0}$ and $w_{M,0}$ in order to calculate $w_{1,1}$ and $w_{M-1,1}$. I have to choose between using the initial conditions $f(x_0)$ and $f(x_M)$, or the boundary conditions $l(0)$ and $r(0)$, which should I use?
I'd think you'd need both, with a caveat.
The initial condition $f(x)$, I'd think, would be for all positions $x_i$ that you're considering. You need to know what the heat distribution looks like everywhere at the beginning. The boundary conditions $l(t), r(t)$ should be consistent with the initial conditions at the beginning ($t=0$). They're the "forcing function" for how the heat is applied at each end, and serve to change the values only at $0$ and $M$ as a function of time.
So ... set your $f(x)$ at the beginning everywhere on $[0,M]$ and then run from there.