# Linear Algebra Functions [Modules]

All linear algebra functions which operate on the matrix as a whole. More...

## Functions

ml_matrixml_matrix::transpose ()
Transposes the matrix.

ml_matrixml_matrix::inv ()
Finds the inverse of the matrix. Principally used for matrix division.

ml_matrix ml_matrix::invp (const ml_matrix &n, int k) const
Returns the product form of the matrix inverse.

ml_matrixml_matrix::mpow (int n)
Returns a matrix raised to a power.

ml_matrix ml_matrix::diag () const
Creates a diagonal matrix from a row or column matrix, or creates a row matrix from a diagonal matrix.

double ml_matrix::trace () const
Returns the trace of the matrix.

ml_matrix ml_matrix::mag () const
Returns a row matrix containing the magnitudes of each column of the matrix.

double ml_matrix::vmag () const
Returns the magnitude of a column or row matrix.

ml_matrixml_matrix::cross (const ml_matrix &n)
Crosses the matrix with the given matrix.

double ml_matrix::dot (const ml_matrix &n) const
Takes the dot product of two column vectors.

ml_matrix ml_matrix::skew_symm () const
Creates a skew symmetric matrix from a vector of three numbers.

ml_matrixml_matrix::unit ()
Makes each column into a row vector.

ml_matrixml_matrix::sign ()
Changes all positive elements into 1, all negative elements into -1.

ml_matrixml_matrix::vunit ()
Unitize a vector matrix by dividing by its vector magnitude.

double ml_matrix::norm () const
Returns the normal of the matrix (largest singular value).

ml_matrixml_matrix::solve_ax_eq_b (const ml_matrix &a)
Solve the general system of linear equations AX=B.

ml_matrixml_matrix::row_mult (int row, double fac)
ml_matrix transpose (const ml_matrix &m)
Transposes the matrix.

ml_matrix inv (const ml_matrix &m)
Finds the inverse of the matrix. Principally used for matrix division.

ml_matrix mpow (const ml_matrix &m, int n)
Raises the matrix m to the power n.

ml_matrix cross (const ml_matrix &m, const ml_matrix &y)
Crosses the two matrices.

ml_matrix unit (const ml_matrix &m)
Makes each column into a row vector.

ml_matrix sign (const ml_matrix &m)
Changes all positive elements into 1, all negative elements into -1.

ml_matrix svd (ml_matrix &u, ml_matrix &v, const ml_matrix &a)
Returns the singular value decomposition of the third matrix.

ml_matrix vunit (const ml_matrix &m)
Converts the matrix into a unit vector.

ml_matrix solve_ax_eq_b (const ml_matrix &a, const ml_matrix &b)
Solve AX=B.

bool simplex (ml_matrix &x, ml_matrix c, ml_matrix a, ml_matrix b, double max_val)
Uses the simplex method to minimize the cost when solving the problem au = b and the cost is cu.

void simplex2 (ml_matrix a, ml_matrix c, ml_matrix &x, ml_int_array &s, ml_int_array &g, ml_int_array &gu, ml_matrix &b_inv, double max_val)
Computes the solution to the simplex problem with an optional maximum constraint.

## Function Documentation

 ml_matrix & ml_matrix::transpose ( ) ` [inherited]`
 Transposes the matrix. Returns:Returns a transposed matrix

 ml_matrix & ml_matrix::inv ( ) ` [inherited]`
 Finds the inverse of the matrix. Principally used for matrix division. This function can return an error matrix of ml_non_invertible_matrix if the matrix is empty, non-square, or otherwise non-invertible. Returns:Returns the inverse of the matrix.

 ml_matrix ml_matrix::invp ( const ml_matrix & v, int k ) const` [inherited]`

Returns the product form of the matrix inverse.

This function can return an error matrix of type ml_bad_index if the specified column is out of range.

Parameters:
 v The matrix to be used in the computation. k The column index of v.

 ml_matrix & ml_matrix::mpow ( int n ) ` [inherited]`

Returns a matrix raised to a power.

Parameters:
 n The power to raise the matrix to
Returns:
Returns the matrix raised to the power n

 ml_matrix ml_matrix::diag ( ) const` [inherited]`
 Creates a diagonal matrix from a row or column matrix, or creates a row matrix from a 2-dimensional matrix's diagonal. Returns:Returns a new matrix.

 double ml_matrix::trace ( ) const` [inherited]`
 Calculates the trace of the matrix. A trace of a matrix is the summation of the diagonal. Returns:Returns the trace of the matrix.

 ml_matrix ml_matrix::mag ( ) const` [inherited]`
 Calculates the magnitudes of each column of the matrix. Returns:Returns a new row matrix containing the magnitudes of each column of the matrix.

 double ml_matrix::vmag ( ) const` [inherited]`
 Calculates the scalar magnitude of a column or row matrix. Returns:Returns the scalar magnitude of a column or row matrix.

 ml_matrix & ml_matrix::cross ( const ml_matrix & m ) ` [inherited]`

Crosses the matrix with matrix m.

Parameters:
 m The second matrix.
Returns:
Returns m cross n.

 double ml_matrix::dot ( const ml_matrix & v ) const` [inherited]`
 Takes the dot product of this matrix and the given matrix.

 ml_matrix ml_matrix::skew_symm ( ) const` [inherited]`
 Creates a skew symmetric matrix, the matrix form of the cross product, from a vector of three numbers. Returns:Returns a new matrix equal to the skew symmetric of the matrix.

 ml_matrix & ml_matrix::unit ( ) ` [inherited]`
 Makes each column into a row vector.

 ml_matrix & ml_matrix::sign ( ) ` [inherited]`
 Changes all positive elements into 1, all negative elements into -1.

 ml_matrix & ml_matrix::vunit ( ) ` [inherited]`
 Unitize a vector matrix by dividing by its vector magnitude. Returns:Returns the unit vector of the matrix.

 double ml_matrix::norm ( ) const` [inherited]`
 Returns the normal of the matrix (largest singular value).

 ml_matrix & ml_matrix::solve_ax_eq_b ( const ml_matrix & a ) ` [inherited]`

Attempt to solve the generalize system of linear equations AX = B. This matrix is used as B, and on return will be X if a solution was found.

This function can return an error matrix of type ml_size_mismatch if a is not a square matrix, or if the number of rows in a does not match the number of columns in this matrix.

Parameters:
 a The A matrix to use in the calculation. Must be square and have the same number of rows as this matrix.
Returns:
Returns itself, to be used in later calculations.

 ml_matrix& ml_matrix::row_mult ( int row, double fac ) ` [inline, inherited]`

Multiplies an entire row by the given factor

Parameters:
 row The row to be multiplied. fac The factor in the multiplication.
Returns:
The matrix.

 ml_matrix transpose ( const ml_matrix & a )
 Creates a new matrix equal to the transpose of the specified matrix. Returns:Returns a transposed matrix.

 ml_matrix inv ( const ml_matrix & m )
 Creates a new matrix equal to the inverse of the specified matrix. Returns:Returns the inverse of the matrix.

 ml_matrix mpow ( const ml_matrix & m, int n )

Creates a new matrix equal to the specified matrix raised to the power n.

Parameters:
 m A square matrix. n The integer power.
Returns:
Returns the resulting matrix.

 ml_matrix cross ( const ml_matrix & m, const ml_matrix & n )

Crosses the matrix m with matrix n.

Parameters:
 m The first matrix. n The second matrix.
Returns:
Returns a new matrix equal to m cross n.

 ml_matrix unit ( const ml_matrix & m )
 Makes each column into a row vector.

 ml_matrix sign ( const ml_matrix & m )

Changes all positive elements into 1, all negative elements into -1.

Parameters:
 m The matrix to be used in the calculation.
Returns:
Returns a new matrix equal to the sign of the original matrix.

 ml_matrix svd ( ml_matrix & U, ml_matrix & V, const ml_matrix & A )

Singular value decomposition, of the form A = U*S*V'. From "Computer Methods for Mathematical Computations," G. E. Forsythe, C. B. Moler, M. A. Malcolm, Prentice-Hall 1977, pp.201-235. The algorithms first reduces the input matrix to bidiagonal form. Then it iteratively reduces the superdiagonal elements to a negligible size, based on machine accuracy.

Parameters:
 U A matrix for storing the unitary matrix U. V A matrix for storing the unitary matrix V. A The matrix to be decomposed.
Returns:
Returns a diagonal matrix with the singular values.

 ml_matrix vunit ( const ml_matrix & m )

Unitize a vector matrix by dividing by its vector magnitude.

Parameters:
 m A one-dimensional matrix.
Returns:
Returns the unit vector of m.

 ml_matrix solve_ax_eq_b ( const ml_matrix & a, const ml_matrix & b )

Attempt to solve the generalize system of linear equations AX = B.

Parameters:
 a The A matrix to use in the calculation. Must be a square matrix. b The B matrix to be used in the calculation. Must have the same number of rows as A.
Returns:
The solution matrix X.

 bool simplex ( ml_matrix & x, ml_matrix c, ml_matrix a, ml_matrix b, double max_val )

Uses the simplex method to minimize the cost when solving the problem au = b and the cost is cu.

Parameters:
 x The solution matrix will be stored in this variable. c Cost vector a Constraint matrix b Right-hand-side, an mx1 column matrix. max_val Maximum constraint on x
Returns:
Returns true if a feasible solution is found, false if not.

 void simplex2 ( ml_matrix a, ml_matrix c, ml_matrix & x, ml_int_array & s, ml_int_array & g, ml_int_array & gU, ml_matrix & BInv, double max_val )

Computes the solution to the simplex problem with an optional maximum constraint.

Parameters:
 a Constraint matrix c Cost vector x State vector s Indices to the constraint matrix g Index to non-basic columns of the constraint matrix gU Index to non-basic columns of the constraint matrix that are at their upper bound BInv Inverse of basic columns max_val Maximum constraint on x*