3
$\begingroup$

I have been working with a finite difference code for the case in which my problem is axysimmetric. This means that all the code I have so far is for 2D In this case the coefficient matrix isn't hard to set up. For example, a coefficient matrix would be of the form:

$$ \begin{bmatrix} -4 & 1 & 0 & 0 & 1 \\ 1 & -4 & 1 & 0 & 0 & 1 \\ 0 & 1 & -4 & 1 & 0 & 0 & 1 \\ 0 & 0 & 1 & -4 & 1 & 0 & 0 & 1 \\ 1 & 0 & 0 &1 & -4 & 1 & 0 & 0 & 1 \\ & 1 & 0 & 0 &1 & -4 & 1 & 0 & 0 & 1 \\ && 1 & 0 & 0 &1 & -4 & 1 & 0 & 0 & 1 \\ &&& \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots \\ \end{bmatrix} $$

Here the $1$'s next to the $-4$'s are due to finite difference equations in the $x$ direction (for example) and the ones far from it are due to the equations in the $y$ direction.

Now I have to extend the code to consider 3D cases, but I'm not sure how you would build a matrix like the above for 3D. I image you end up adding two additional diagonals of $1$'s but I'm not sure exactly where.

Thanks for the help.

(Note: The $-4$'s and $1$'s are just for the example, my specific problem has variable coefficients, but this makes no difference for the structure of the matrix.)

$\endgroup$
  • $\begingroup$ does not your coefficient matrix depend on how you have labelled, you number the grid points row-wise or colum-wise and the finite differencing your pde. i am not sure how you even got your string of ones above the super diagonal only two places farther. i would have guessed that it to the breadth of the domain. $\endgroup$ – abel Dec 6 '14 at 16:28
  • $\begingroup$ There is a small error in the matrices, that is all the matrices are diagonal 1. With $-k, -k, \cdots, -k$ on the diagonal of the matrix $D_k$. 2. With the diagonal $D_k, D_k, \cdots, D_k$ for the matrix $E_k$. 3. with the diagonal $E_k, E_k, \cdots, E_k$ for the matrix $F_k$. The $1$'s and the identity matrices will be on the upper and lower sub-diagonals. $\endgroup$ – Fatima ABOUD Feb 13 '18 at 14:26
4
$\begingroup$

Let $D_k \in \mathbb{R}^{n \times n}$ with \begin{align} D_k = \begin{pmatrix} -k & 1 & 0 & 0& ... & 0\\ 1 & -k & 1 & 0& ... &0 \\ & \ddots &\ddots&\ddots&\\ 0 & 0& 0& 1 & -k&1 \end{pmatrix} \end{align} Then we know, that the $1D$ finite difference matrix is given by $D_2$. Let $I$ be the $n\times n$ identity matrix. For the $2D$ case we have the matrix $E_k\in \mathbb{R}^{n^2 \times n^2}$ defined as \begin{align} E_k=\begin{pmatrix} D_k & I & 0 & 0&... & 0 \\ I & D_k & I& 0&...&0\\ & \ddots &\ddots&\ddots&\\ 0 & 0&0&I &D_k & I \end{pmatrix} \end{align} Then the $2D$ finite difference is given by $E_4$. Now let $J$ be the $n^2 \times n^2$ identity matrix. For the $3D$ case we have the matrix $F_k\in \mathbb{R}^{n^3 \times n^3}$ defined as \begin{align} F_k=\begin{pmatrix} E_k & J & 0 & 0&... & 0 \\ J & E_k & J& 0&...&0\\ & \ddots &\ddots&\ddots&\\ 0 & 0&0&J &E_k & J \end{pmatrix} \end{align} And obviously, the $3D$ finite difference matrix is given by $F_6$

$\endgroup$
  • $\begingroup$ Thanks, this was what I needed. $\endgroup$ – Sciencertobe Dec 8 '14 at 11:37
  • $\begingroup$ Of course, one would try to avoid to create the matrix in its explicit form, since only 6 of the $n^3$ elements per row are nonzero. $\endgroup$ – k1next Dec 8 '14 at 12:59
  • $\begingroup$ Yes, of course :) I just wanted to be sure where the extra diagonals go. $\endgroup$ – Sciencertobe Dec 8 '14 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.