# Mathematical Properties

## General properties

The RowCount and ColumnCount properties returns the number of rows and columns in the matrix.

The ElementOrder property specifies the order in which elements are stored. Possible values are ColumnMajor , RowMajor, and NotApplicable. These are enumerated by the MatrixElementOrder enumeration type.

ColumnMajor order means that, whenever possible, the elements in the same column of a matrix are stored in a contiguous block of memory. Likewise, RowMajor order means that elements in the same row are stored contiguously. Most algorithms have been optimized for column-major order. Conversions are performed as necessary.

For some matrix types, the element order is meaningless. In this case, the value is NotApplicable.

The ToArray method returns an array containing the elements of the matrix. The desired element order can be specified as a MatrixElementOrder value. The default is ColumnMajor. This method always returns a new array.

The following example illustrates these properties:

C#
``````var m = Matrix.CreateFromArray(2, 2, new[] { 1.0, 2.0, 4.0, 8.0 },
MatrixElementOrder.RowMajor);
var rowCount = m.RowCount; // 2
var columnCount = m.ColumnCount; // 2
var elements = m.ToArray();
// elements -> { 1.0, 4.0, 2.0, 8.0 }
var elementsByRow = m.ToArray(MatrixElementOrder.RowMajor);
// elementsByRow -> { 1.0, 2.0, 4.0, 8.0 }``````

## Mathematical properties

Most common mathematical properties of matrices are costly to compute, in particular for large matrices. Because of this, these properties have been implemented as methods.

The norm of a matrix is a measure for the size of a matrix. Unlike vector norms, matrix norms are often hard to calculate. The easiest to calculate is the Frobenius-norm, defined as the square root of the sum of the squares of the elements of a matrix. The FrobeniusNorm method returns the Frobenius norm.

The one-norm of a matrix is defined as the maximum of the sum of the absolute values of the elements in each column. It is available through the OneNorm method.

The infinity-norm of a matrix is defined as the maximum of the sum of the absolute values of the elements in each row. It is available through the InfinityNorm method.

The two-norm of a matrix is defined as the largest increase in the length (two-norm) of a vector when it is multiplied by the matrix. This corresponds to the largest singular value of the matrix. It is available through the TwoNorm method.

The trace of a matrix is the sum of the diagonal elements. It is available through the Trace method.

C#
``````var m = Matrix.CreateFromArray(2, 2, new[] { 1.0, 2.0, 4.0, 8.0 },
MatrixElementOrder.RowMajor);
var rowCount = m.RowCount; // 2
var columnCount = m.ColumnCount; // 2
var elements = m.ToArray();
// elements -> { 1.0, 4.0, 2.0, 8.0 }
var elementsByRow = m.ToArray(MatrixElementOrder.RowMajor);
// elementsByRow -> { 1.0, 2.0, 4.0, 8.0 }``````

Other properties, such as the inverse, transpose, and determinant are covered in the section on Solving Systems Of Linear Equations.