For small matrices (e.g. less than 1000x1000) dense matrices work well. But in practice there are a lot of problems where much larger matrices are needed, but where almost all values are zero (often with non-zero values close to the diagonal). With sparse matrices it is possible to handle very large matrices in cases where the dense structure is unfeasible (because it needs too much memory or is way to expensive to compute with CPU-time wise).
Note that as of today the Math.NET Numerics direct matrix decomposition methods are optimized for dense matrices only; use iterative solvers for sparse data instead.
Regarding types, in Math.NET Numerics v3 the hierarchy for double-valued matrices is as follows:
Matrix<double>
|- Double.Matrix
|- Double.DenseMatrix
|- Double.SparseMatrix
|- Double.DiagonalMatrix
With Matrix<T>
I refer to the full type MathNet.Numerics.LinearAlgebra.Matrix<T>
, with
Double.Matrix
to MathNet.Numerics.LinearAlgebra.Double.Matrix
, etc.
Matrix<double>
: always declare all variables, properties and arguments using this generic type only. Indeed, in most cases this is the only type needed in user code.
Double.Matrix
: do not use
Double.DenseMatrix
: use for creating a dense matrix only - if you do not wish to use the builder (Matrix<double>.Build.Dense...
)
Double.SparseMatrix
: use for creating a sparse matrix only - if you do not wish to use the builder
Double.DiagonalMatrix
: use for creating a diagonal matrix only - if you do not wish to use the builder