0
$\begingroup$

I read the way of storing the five or seven point laplace matrix for some poisson problem but I don't understand how can i multiply, add and subtract this stored sparse matrix by a vector or another matrix?

The way says that we just store the diagonal entries which are the coefficients of the i,j,k unknown in adiag matrix and the coefficients of the i+,j,k neighbours will be stored in another array ax and for the j neighbours as well.

$\endgroup$
2
  • $\begingroup$ Where did you read this? $\endgroup$
    – nicoguaro
    Commented Jul 11, 2017 at 1:39
  • $\begingroup$ In Robert bridson's book fluid simulation for computer graphics $\endgroup$
    – Anas Alaa
    Commented Jul 11, 2017 at 10:12

1 Answer 1

2
$\begingroup$

Think about it this way: in your matrix, you know exactly where the entries are nonzero (and you store what these values are), and everything else is zero. If you just write down the usual matrix-vector product,

for (i=1...N)
  for (j=1...N)
    output[i] += matrix[i,j] * input[j];

then you realize that most of these additions just add zeros because the matrix entry is zero. You can avoid all of those unnecessary operations if you remember where your nonzero entries are, and then only do those products and additions that are necessary. This is in essence what the book is suggesting: have a way to know where the nonzero entries of the matrix are, store what their values are, and then shrink the loop above to only those operations that are necessary.

$\endgroup$
2
  • $\begingroup$ So if the matrix has the non zeros at the diagonal so we store them in an array adiag(i, j, k) and for the coefficients of the neighbours of the cell (i, j, k) in the positive x we will use ax(i, j, k) and ay (i, j, k) how can we do the multiplication? $\endgroup$
    – Anas Alaa
    Commented Jul 12, 2017 at 12:03
  • $\begingroup$ @AnasAlaa -- you just repeat your original question. Have you thought about how my answer could get you closer to understanding how this may be done? $\endgroup$ Commented Jul 19, 2017 at 3:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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