Why is dense format better than sparse format for small sizes?

Issue

This Content is from Stack Overflow. Question asked by Kilkik

We consider the following code on Matlab with N an integer.

diag = 3*speye(N,N);           % diagonal
subd=-sparse(2:N,1:N-1,1,N,N);
A=diag+subd+2*subd';
C=full(A);

If I am not wrong, sparse format keeps only non-zero entries, so it needs less memory. I noticed that when N=2,…,6, the size of A is bigger than the size of C even if A is in sparse format. Can someone explain why ?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?