I am trying to solve the following PDE using finite difference:
\begin{aligned} \frac{\partial}{\partial t} u(x, t)-\frac{\partial^2}{\partial x^2} u(x, t) & =x, \quad x \in(0,1), \quad t \in(0,1), \\ u(x, 0) & =x(1-x), \quad x \in[0,1], \\ u(x, t) & =u(x+1, t), \quad x \in \mathbb{R} \quad t \in[0,1] . \end{aligned}
Here is the work so far:
I divide the domain into grid points $x_n=n \Delta x$, for $n=0,1,2, \ldots, N$, with $\Delta x=1 / N$, and time steps $t_m=m \Delta t$, for $m=0,1, \ldots, M$, with $\Delta t=1 / M$. Use the following approximations:
- The value of $u$ at the grid point $(n \Delta x, m \Delta t)$ is approximately $u_{n m}$.
- The time derivative of $u$ at $(n \Delta x, m \Delta t)$ is approximated by $\frac{u_{n, m+1}-u_{n m}}{\Delta t}$.
- The second spatial derivative of $u$ at $(n \Delta x, m \Delta t)$ is approximated by $\frac{u_{n+1, m}-2 u_{n m}+u_{n-1, m}}{(\Delta x)^2}$.
Substituting these approximations into the equation gives the finite difference method: $$ \frac{u_{n, m+1}-u_{n m}}{\Delta t}=\frac{u_{n+1, m}-2 u_{n m}+u_{n-1, m}}{(\Delta x)^2}+x_n $$
For $m=0, \ldots, M-1$, $$ u_{n, m+1}=(1-2 \lambda) u_{n m}+\lambda\left(u_{n+1, m}+u_{n-1, m}\right)+n \Delta x \Delta t \quad \text { for } n=1, \ldots, N $$ where $\lambda=\Delta t /(\Delta x)^2$ and
- For the boundary conditions, $u_{0 m}=u_{N m}$ and $u_{N+1, m}=u_{1 m}$ for $m=0,1, \ldots, M$.
- The initial conditions are given by $u_{n 0}=x_n\left(1-x_n\right)$ for $n=0,1, \ldots, N$.
What I ave difficulty understanding is how to formulate this in matrix equation form i.e $Au=b$. Specifically, I don't see how to fill the elements in the matrix A. So far I have figured out that the main diagonal i.e n=m should be $A_{n,m}=1+2\lambda$