This may seem trivial, but I'm having some trouble deriving the finite difference form of the heat equation with a thermal conductivity function $a(x)$ depending on $x$:
$$\frac{\partial u(x, t)}{\partial t} = \frac{\partial }{\partial x}[a(x)\frac{\partial u(x, t)}{\partial x}]$$
I find some trouble deriving the right hand side. Let $h$ be the space step, and $x_{i−1}=x_i−h$ and $x_{i+1}=x_i+h$. I want to evaluate the right hand side on node $i$. If I take centered differences I get:
$$\begin{align*}\left\{\frac{\partial}{\partial x}\left[ a(x)\frac{\partial \, u(x, t)}{\partial x}\right]\right\}_i &= \frac{\left[a(x)\frac{\partial\, u(x, t)}{\partial x}\right]_{i+1/2} - \left[a(x)\frac{\partial \, u(x, t)}{\partial x}\right]_{i-1/2}}{h} \\ &= \frac{a_{i+1/2}\left[\frac{u_{i+1}-u_{i}}{h}\right] - a_{i-1/2}\left[\frac{u_{i}-u_{i-1}}{h}\right]}{h} \end{align*}$$
Is this ok? The conductivities should be in between the nodes I'm calculating? (intuitively it seems this is reasonable). Is there a way, for example by using forward or backward differences, to use conductivity nodes that overlap with the nodes I'm calculating (I calculate only the interger indexed nodes)? Can I mix a centered difference approach for one derivative and a backward or forward approach for the other one?
I would really appreciate any hint.
Thanks in advance,
Federico