Crank Nicolson finite difference method for the parabolic PDE

493 Views Asked by At

Well I have to find the numerical solutions through MATLAB using Crank Nicolson fdm for the parabolic PDE


$u_{t} = u_{xx}+xu_{x}-3u$ , $0 < x < 1$

$u(x,0) = x^{2}+1$, $0 \leq x \leq 1$

$u(o,t) = e^{-t}$, $u(1,t)=2e^{-t}$


I tried to change the equation with


$u_{t} = \frac{u_{ij}-u_{ij-1}}{k}$

$u_{xx} = \frac{1}{2}\{ \ \frac{u_{i+1j}\ \ -2u_{ij}\ \ +u_{i-1j}}{h^{2}} \ + \ \frac{u_{i+1j-1}\ \ -2u_{ij-1}\ +u_{i-1j-1}}{h^{2}}\ \ \}$

$u_{x} = \frac{u_{ij}-u_{i-1j}}{h}$

$u = u_{ij}$


Therefore I get

$u_{ij}+u_{ij-1} \ = \ \frac{k}{2h^{2}}u_{i+1j} \ - (\frac{k}{h^{2}}-\frac{k}{h}x+3k)u_{ij} \ +\ (\frac{k}{2h^{2}}-\frac{k}{h}x)u_{i-1j} \ + \ \frac{k}{2h^{2}}u_{i+1j-1} \ \ + \ (2-\frac{k}{h^{2}})u_{ij-1} \ + \ \frac{k}{2h^{2}}u_{i-1j-1}$

And now I am stuck with making matrix equation as $Ax=b$...

Can anybody help?

Thanks :)

1

There are 1 best solutions below

0
On

From the beginning you are considering a 1D case, so with your notation:

  • $i$ is for tat spatial coordinate
  • $j$ is for the time (the step)

With the notation you obtain a system like: $$ A\mathbf{u} = \mathbf{b} $$ where $\mathbf{u} = (u_{1,j} , \dots,u_{n,j})^T$, with $j$ the next step (as your notation).

Now you have the final formula for the $i$-node, I didn't check it, from this equation you obtain the $i$-row of the matrix $A$. You need to move all the terms for the next step, $j$, to left side and all the terms of the previous time step, $j-1$, to right, i.e. the known term.

Inside the $i$-equation you use only the nodes $i-1, i, i+1$, so the matrix is tridiagonal, with a shift of the row. For few nodes try to write the equitation for every node and you can see the structure.

After this you must set the boundary condition to the matrix and $\mathbf{b}$.

At this link you can find a similar example (pag 1 to 3).