Solving Laplace's equation using finite differences

3.8k Views Asked by At

I having coding in MatLab to approximate solutions to Laplace's equation in 2D using finite differences. I was able to do it without much problem. I learnt about how to implement this using this: https://www.youtube.com/watch?v=_IuaBfd3H80

Now I have moved a step further. I am trying to code in 3D now, and I am stuck and confused. If you go to the link above, and jump to time 42:21 he talks about how to modify matrices by looking at neighboring nodes (is it a BC or its another unknown etc). He is talking in context of 2D and everything makes sense. I simply don't know how to about it in 3D, to be specific, hwo would that slide at 42:21 look like if he was talking in context of 3D. Thank you for your time!

1

There are 1 best solutions below

0
On

6-pt

In 3D case, you have a 7-point stencil (see above picture took from wikipedia), the center node is $(i,j,k)$. It has six neighbor nodes: $(i+1,j,k)$, $(i-1,j,k)$, $(i,j+1,k)$, $(i,j-1,k)$, $(i,j,k+1)$, and $(i,j,k-1)$.

Then the central difference to approximate the second derivative is: $$ \frac{\partial^2 u}{\partial x^2}\Bigg|_{(i,j,k)} \approx \frac{u_{i+1,j,k} -2u_{i,j,k}+ u_{i-1,j,k}}{h^2}, $$ where the second and third components are holding fixed, similar for second derivative in $y$ and $z$.