Linear Algebra
All linear algebra functionality for Math.Net can be found under the MathNet.Numerics.LinearAlgebra namespace. This namespace is divided up into four different subnamespaces
- MathNet.Numerics.LinearAlgebra.Double: for doing real linear algebra using double floating point precision.
- MathNet.Numerics.LinearAlgebra.Single: for doing real linear algebra using single floating point precision.
- MathNet.Numerics.LinearAlgebra.Complex: for doing complex linear algebra using double floating point precision.
- MathNet.Numerics.LinearAlgebra.Complex32: for doing complex linear algebra using single floating point precision.
Another distinction we make in the linear algebra library is in different matrix storage representations. Currently, Math.Net supports three different matrix storage representations (for each of the four different types mentionned above):
- DenseMatrix: for representing arbitrary matrices.
- SparseMatrix: for representing sparse matrices.
- DiagonalMatrix: for representing diagonal matrices.
The final feature of the linear algebra library is which computational engine executes the calculations. The default configuration for Math.Net uses all managed code to execute matrix operations. Since managed code executes on the x87 unit, it cannot use any of the special vectorized instructions to speed up calculations. For very large matrices this will have an impact on performance compared to native implementations. We suggest you vote on Microsoft Connect to encourage the CLR team to implement this feature in the future. Nonetheless, Math.Net also support native providers for executing linear algebra computations. To configure these providers, use the following code
// Use the ATLAS native linear algebra provider. MathNet.Numerics.Control.LinearAlgebraProvider = new AtlasLinearAlgebraProvider();Currently, Math.Net supports Atlas and Intel MKL providers. We ancourage the community to contribute other providers (such as GPU backed computations).
Samples
A short sample for creating a matrix and a vector and multiplying them together can be found below.
using MathNet.Numerics.LinearAlgebra.Double; // Create a vector of dimension 5 with 4.0 in every entry. var x = new DenseVector(5, 4.0); // Create a 3 by 5 matrix with 2.0 in every entry. var A = new DenseMatrix(3, 5, 2.0); // Multiply the matrix and the vector. var y = A * x;



