14.2.20 Class Matrix

mosek.fusion.Matrix

Base class for all matrix objects. It can be used to create and manipulate matrices of constant coefficients both in dense and sparse format. To operate with matrices containing variables and linear expressions use the classes Expr and Variable.

Members:

Matrix.Get – Get a single entry.

Matrix.GetDataAsArray – Return a dense array of values.

Matrix.GetDataAsTriplets – Return the matrix data in sparse triplet format.

Matrix.IsSparse – Returns true if the matrix is sparse.

Matrix.NumColumns – Returns the number of columns in the matrix.

Matrix.NumNonzeros – Returns the number of non-zeros in the matrix.

Matrix.NumRows – Returns the number of rows in the matrix.

Matrix.ToString – Get a string representation of the matrix.

Matrix.Transpose – Transpose the matrix.

Static members:

Matrix.Antidiag – Create a sparse square matrix with a given vector as anti-diagonal.

Matrix.Dense – Create a dense matrix from the given data.

Matrix.Diag – Create a sparse square matrix with a given vector as diagonal.

Matrix.Eye – Create the identity matrix.

Matrix.Ones – Create a matrix filled with all ones.

Matrix.Sparse – Create a sparse matrix from the given data.

Matrix.Antidiag
Matrix Matrix.Antidiag(double[] d)
Matrix Matrix.Antidiag(double[] d, int k)
Matrix Matrix.Antidiag(int n, double val)
Matrix Matrix.Antidiag(int n, double val, int k)

Create a sparse square matrix with a given vector as anti-diagonal.

Parameters:
  • d (double[]) – The anti-diagonal vector.

  • k (int) – The anti-diagonal index. \(k=0\) is the default and means the main anti-diagonal. \(k>0\) means above, and \(k<0\) means below the main anti-diagonal.

  • n (int) – The dimension of the matrix.

  • val (double) – Use this value for all anti-diagonal elements.

Return:

(Matrix)

Matrix.Dense
Matrix Matrix.Dense(double[,] data)
Matrix Matrix.Dense(int dimi, int dimj, double[] data)
Matrix Matrix.Dense(int dimi, int dimj, double value)
Matrix Matrix.Dense(Matrix other)

Create a dense matrix from the given data.

Parameters:
  • data (double[,]) – A one- or two-dimensional array of matrix coefficients.

  • data (double[]) – A one- or two-dimensional array of matrix coefficients.

  • dimi (int) – Number of rows.

  • dimj (int) – Number of columns.

  • value (double) – Use this value for all elements.

  • other (Matrix) – Create a dense matrix from another matrix.

Return:

(Matrix)

Matrix.Diag
Matrix Matrix.Diag(double[] d)
Matrix Matrix.Diag(double[] d, int k)
Matrix Matrix.Diag(int n, double val)
Matrix Matrix.Diag(int n, double val, int k)
Matrix Matrix.Diag(Matrix[] md)
Matrix Matrix.Diag(int num, Matrix mv)

Create a sparse square matrix with a given vector as diagonal.

Parameters:
  • d (double[]) – The diagonal vector.

  • k (int) – The diagonal index. \(k=0\) is the default and means the main diagonal. \(k>0\) means above, and \(k<0\) means below the main diagonal.

  • n (int) – The dimension of the matrix.

  • val (double) – Use this value for all diagonal elements.

  • md (Matrix[]) – A list of square matrices that are used to create a block-diagonal square matrix.

  • num (int) – Number of times to repeat the mv matrix.

  • mv (Matrix) – A matrix to be repeated in all blocks of a block-diagonal square matrix.

Return:

(Matrix)

Matrix.Eye
Matrix Matrix.Eye(int n)

Construct the identity matrix of size \(n\).

Parameters:

n (int) – The dimension of the matrix.

Return:

(Matrix)

Matrix.Get
double Get(int i, int j)

Get a single entry.

Parameters:
  • i (int) – Row index.

  • j (int) – Column index.

Return:

(double)

Matrix.GetDataAsArray
double[] GetDataAsArray()

Return the matrix elements as a dense array in row-major format.

Return:

(double[])

Matrix.GetDataAsTriplets
void GetDataAsTriplets(int[] subi, int[] subj, double[] val)

Return the matrix data in sparse triplet format. Data is copied to the arrays subi, subj and val which must be pre-allocated to hold at least the number of non-zeros in the matrix.

The data returned must be ordered with subi as primary key and subj as secondary key.

Parameters:
  • subi (int[]) – Row subscripts are returned in this array.

  • subj (int[]) – Column subscripts are returned in this array.

  • val (double[]) – Coefficient values are returned in this array.

Matrix.IsSparse
bool IsSparse()

Returns true if the matrix is sparse.

Return:

(bool)

Matrix.NumColumns
int NumColumns()

Returns the number of columns in the matrix.

Return:

(int)

Matrix.NumNonzeros
long NumNonzeros()

Returns the number of non-zeros in the matrix.

Return:

(long)

Matrix.NumRows
int NumRows()

Returns the number of rows in the matrix.

Return:

(int)

Matrix.Ones
Matrix Matrix.Ones(int n, int m)

Construct a matrix filled with ones.

Parameters:
  • n (int) – Number of rows.

  • m (int) – Number of columns.

Return:

(Matrix)

Matrix.Sparse
Matrix Matrix.Sparse(int nrow, int ncol, int[] subi, int[] subj, double[] val)
Matrix Matrix.Sparse(int[] subi, int[] subj, double[] val)
Matrix Matrix.Sparse(int[] subi, int[] subj, double val)
Matrix Matrix.Sparse(int nrow, int ncol, int[] subi, int[] subj, double val)
Matrix Matrix.Sparse(int nrow, int ncol)
Matrix Matrix.Sparse(double[,] data)
Matrix Matrix.Sparse(Matrix[][] blocks)
Matrix Matrix.Sparse(Matrix mx)

Create a sparse matrix from the given data.

Parameters:
  • nrow (int) – Number of rows.

  • ncol (int) – Number of columns.

  • subi (int[]) – Row subscripts of non-zero elements.

  • subj (int[]) – Column subscripts of non-zero elements.

  • val (double[]) – Coefficients of non-zero elements.

  • val (double) – Coefficients of non-zero elements.

  • data (double[,]) – Dense data array.

  • blocks (Matrix[][]) – The matrix data in block format. All elements in a row must have the same height, and all elements in a column must have the same width. Entries that are null will be interpreted as a block of zeros whose height and width are deduced from the other elements in the same row and column. Any row that contains only null entries will have height 0, and any column that contains only null entries will have width 0.

  • mx (Matrix) – A Matrix object.

Return:

(Matrix)

Matrix.ToString
string ToString()

Get a string representation of the matrix.

Return:

(string)

Matrix.Transpose
Matrix Transpose()

Transpose the matrix.

Return:

(Matrix)