Generated by DocFX

Class Matrix

A matrix is represented by a nested list of double point numbers.
So, you would write simply [[1,0],[0,1]] to create a 2x2 identity matrix.

Inheritance
System.Object
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>
Matrix
Inherited Members
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.get_Item(System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.set_Item(System.Int32, System.Object)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Add(System.Collections.Generic.List<System.Double>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.AddRange(System.Collections.Generic.IEnumerable<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.AsReadOnly()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.BinarySearch(System.Int32, System.Int32, System.Collections.Generic.List<System.Double>, System.Collections.Generic.IComparer<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.BinarySearch(System.Collections.Generic.List<System.Double>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.BinarySearch(System.Collections.Generic.List<System.Double>, System.Collections.Generic.IComparer<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Clear()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Contains(System.Collections.Generic.List<System.Double>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.ConvertAll<TOutput>(System.Converter<System.Collections.Generic.List<System.Double>, TOutput>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.CopyTo(System.Int32, System.Collections.Generic.List<System.Double>[], System.Int32, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.CopyTo(System.Collections.Generic.List<System.Double>[])
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.CopyTo(System.Collections.Generic.List<System.Double>[], System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Exists(System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Find(System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.FindAll(System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.FindIndex(System.Int32, System.Int32, System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.FindIndex(System.Int32, System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.FindIndex(System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.FindLast(System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.FindLastIndex(System.Int32, System.Int32, System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.FindLastIndex(System.Int32, System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.FindLastIndex(System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.ForEach(System.Action<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.GetEnumerator()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.GetRange(System.Int32, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.IndexOf(System.Collections.Generic.List<System.Double>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.IndexOf(System.Collections.Generic.List<System.Double>, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.IndexOf(System.Collections.Generic.List<System.Double>, System.Int32, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Insert(System.Int32, System.Collections.Generic.List<System.Double>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.InsertRange(System.Int32, System.Collections.Generic.IEnumerable<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.LastIndexOf(System.Collections.Generic.List<System.Double>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.LastIndexOf(System.Collections.Generic.List<System.Double>, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.LastIndexOf(System.Collections.Generic.List<System.Double>, System.Int32, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Remove(System.Collections.Generic.List<System.Double>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.RemoveAll(System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.RemoveAt(System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.RemoveRange(System.Int32, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Reverse()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Reverse(System.Int32, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Sort()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Sort(System.Collections.Generic.IComparer<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Sort(System.Comparison<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Sort(System.Int32, System.Int32, System.Collections.Generic.IComparer<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.Generic.IEnumerable<System.Collections.Generic.List<System.Double>>.GetEnumerator()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.ICollection.CopyTo(System.Array, System.Int32)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IEnumerable.GetEnumerator()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.Add(System.Object)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.Contains(System.Object)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.IndexOf(System.Object)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.Insert(System.Int32, System.Object)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.Remove(System.Object)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.ToArray()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.TrimExcess()
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.TrueForAll(System.Predicate<System.Collections.Generic.List<System.Double>>)
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Capacity
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Count
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.Item[System.Int32]
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.Generic.ICollection<System.Collections.Generic.List<System.Double>>.IsReadOnly
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.ICollection.IsSynchronized
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.ICollection.SyncRoot
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.IsFixedSize
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.IsReadOnly
System.Collections.Generic.List<System.Collections.Generic.List<System.Double>>.System.Collections.IList.Item[System.Int32]
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Syntax
public class Matrix : List<List<double>>, IList<List<double>>, ICollection<List<double>>, IReadOnlyList<List<double>>, IReadOnlyCollection<List<double>>, IEnumerable<List<double>>, IList, ICollection, IEnumerable

Constructors

| Improve this Doc View Source

Matrix()

Initializes an empty matrix.

Declaration
public Matrix()

Methods

| Improve this Doc View Source

Construct(Int32, Int32)

Constructs a matrix by given number of rows and columns.
All the parameters are set to zero.

Declaration
public static Matrix Construct(int rows, int columns)
Parameters
Type Name Description
System.Int32 rows

A positive integer, for the number of rows.

System.Int32 columns

A positive integer, for the number of columns.

Returns
Type Description
Matrix

A matrix reflecting the number of rows and columns provided.

| Improve this Doc View Source

Decompose(Matrix, out Int32[])

This routine uses Doolittle's method with partial pivoting to decompose the n x n matrix A,
into a unit lower triangular matrix L and an upper triangular matrix U and P is a permutation array
such that PA = LU. With this method you can always have a LU decomposition, rather than LU factorization.
The LU decomposition with pivoting always exists, even if the matrix is singular, so the constructor will never fail.
The primary use of the LU decomposition is in the solution of square systems of simultaneous linear equations.
The LUP decomposition provides a more robust method of solving linear systems than LU decomposition without pivoting, and it is approximately the same cost.
This will fail if non singular.

Declaration
public static Matrix Decompose(Matrix m, out int[] permutation)
Parameters
Type Name Description
Matrix m

Matrix has to be decomposed.

System.Int32[] permutation

The row pivot information is in one-dimensional array.

Returns
Type Description
Matrix

The matrix representing the lower matrix and upper matrix together.

| Improve this Doc View Source

Duplicate(Matrix)

Creates a copy.

Declaration
public static Matrix Duplicate(Matrix matrix)
Parameters
Type Name Description
Matrix matrix

Matrix has to be duplicated.

Returns
Type Description
Matrix

Copied matrix.

| Improve this Doc View Source

FillDiagonal(Int32, Int32, Double)

Fills the diagonal determined by the row and column position of a matrix.

Declaration
public Matrix FillDiagonal(int row, int column, double valueToFill)
Parameters
Type Name Description
System.Int32 row

The value row where the diagonal begin.

System.Int32 column

The column value where the diagonal begin.

System.Double valueToFill

The value to fill on the diagonal.

Returns
Type Description
Matrix

A matrix with the identified diagonal filled.

| Improve this Doc View Source

Identity(Int32, Double)

Creates an identity matrix of a given size.

Declaration
public static Matrix Identity(int size, double diagonalValue = 1)
Parameters
Type Name Description
System.Int32 size

The size of the matrix.

System.Double diagonalValue

The value which will be filled the diagonal.

Returns
Type Description
Matrix

Identity matrix of the given size.

| Improve this Doc View Source

Inverse(Matrix)

Computes the inverse of a Matrix.

Declaration
public static Matrix Inverse(Matrix matrix)
Parameters
Type Name Description
Matrix matrix

The matrix to invert.

Returns
Type Description
Matrix

The inverted matrix.

| Improve this Doc View Source

IsValid()

Gets a value indicating whether this matrix is valid.
Matrix is valid when has at least one column and one row and rows have at least 2 elements.

Declaration
public bool IsValid()
Returns
Type Description
System.Boolean

True if it is a valid matrix.

| Improve this Doc View Source

Solve(Matrix, Int32[], Vector)

This routine uses Doolittle's method to solve the linear equation Ax = B.
This routine is called after the matrix A has been decomposed.
The solution proceeds by solving the linear equation Ly = B for y and,
subsequently solving the linear equation Ux = y for x.

Declaration
public static Vector Solve(Matrix LuMatrix, int[] permutation, Vector b)
Parameters
Type Name Description
Matrix LuMatrix

Decomposed matrix in lower and upper triangle.

System.Int32[] permutation

The permutation row, or pivot row interchanged with row i.

Vector b

Column vector.

Returns
Type Description
Vector

The solution of the equation Ax = B is a vector.

| Improve this Doc View Source

ToString()

Constructs the string representation the matrix.

Declaration
public override string ToString()
Returns
Type Description
System.String

Text string.

Overrides
System.Object.ToString()
| Improve this Doc View Source

Transpose()

Transposes a matrix.
This is like swapping rows with columns.

Declaration
public Matrix Transpose()
Returns
Type Description
Matrix

The matrix transposed.

Operators

| Improve this Doc View Source

Addition(Matrix, Matrix)

Adds two matrices.

Declaration
public static Matrix operator +(Matrix a, Matrix b)
Parameters
Type Name Description
Matrix a

First matrix.

Matrix b

Second matrix.

Returns
Type Description
Matrix

The result sum matrix.

| Improve this Doc View Source

Division(Matrix, Double)

Divides a matrix by a constant.

Declaration
public static Matrix operator /(Matrix m, double a)
Parameters
Type Name Description
Matrix m

Matrix has to be multiply.

System.Double a

Value to operate the division.

Returns
Type Description
Matrix

Matrix divided by a constant.

| Improve this Doc View Source

Multiply(Matrix, Matrix)

Multiplies two matrices assuming they are of compatible dimensions.

Declaration
public static Matrix operator *(Matrix a, Matrix b)
Parameters
Type Name Description
Matrix a

First matrix.

Matrix b

Second matrix.

Returns
Type Description
Matrix

The product matrix.

| Improve this Doc View Source

Multiply(Matrix, Double)

Multiplies a matrix by a constant.

Declaration
public static Matrix operator *(Matrix m, double a)
Parameters
Type Name Description
Matrix m

Matrix has to be multiply.

System.Double a

Value to operate the multiplication.

Returns
Type Description
Matrix

Matrix multiply by a constant.

| Improve this Doc View Source

Subtraction(Matrix, Matrix)

Subtracts two matrices.

Declaration
public static Matrix operator -(Matrix a, Matrix b)
Parameters
Type Name Description
Matrix a

First matrix.

Matrix b

Second matrix.

Returns
Type Description
Matrix

The subtraction matrix.

Implements

System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IReadOnlyList<T>
System.Collections.Generic.IReadOnlyCollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IList
System.Collections.ICollection
System.Collections.IEnumerable

Extension Methods

ExtendedEnumerable.Unique<T>(IEnumerable<T>, Func<T, T, Boolean>)