Frobby  0.9.5
Functions
Matrix.cpp File Reference
#include "stdinc.h"
#include "Matrix.h"
#include "BigIntVector.h"
#include "ColumnPrinter.h"
#include <utility>
#include <sstream>

Go to the source code of this file.

Functions

bool operator== (const Matrix &a, const Matrix &b)
 
ostream & operator<< (ostream &out, const Matrix &mat)
 
void print (FILE *file, const Matrix &mat)
 
void print (ColumnPrinter &pr, const Matrix &mat)
 
void product (Matrix &prod, const Matrix &a, const Matrix &b)
 Sets prod to a * b. More...
 
void transpose (Matrix &trans, const Matrix &mat)
 Sets trans to the transpose of mat. More...
 
void transpose (Matrix &mat)
 Transpose mat inplace. More...
 
void addMultiplyRow (Matrix &mat, size_t resultRow, size_t sourceRow, const mpq_class &mult)
 Adds mult times row sourceRow to row resultRow of mat. More...
 
void multiplyRow (Matrix &mat, size_t row, const mpq_class &mult)
 Multiplies row row with mult. More...
 
void swapRows (Matrix &mat, size_t row1, size_t row2)
 Swaps row row1 and row row2 of mat. More...
 
bool rowReduce (Matrix &mat)
 Reduces mat to row-echelon form, i.e. More...
 
void rowReduceFully (Matrix &mat)
 Reduces mat to reduced row-echelon form, i.e. More...
 
void subMatrix (Matrix &sub, const Matrix &mat, size_t rowBegin, size_t rowEnd, size_t colBegin, size_t colEnd)
 Sets sub to the sub-matrix of mat with rows in the interval [rowBegin, rowEnd) and columns in the interval [colBegin, colEnd). More...
 
void copyRow (Matrix &target, size_t targetRow, const Matrix &source, size_t sourceRow)
 Copies row sourceRow from source to row targetRow of target. More...
 
bool inverse (Matrix &inv, const Matrix &mat)
 Sets inv to the inverse of mat. More...
 
size_t matrixRank (const Matrix &matParam)
 Returns the rank of mat. More...
 
void nullSpace (Matrix &basis, const Matrix &matParam)
 Sets the columns of basis to a basis of the null space of mat. More...
 
bool solve (Matrix &sol, const Matrix &lhs, const Matrix &rhs)
 Sets sol to some matrix such that lhs*sol=rhs and returns true if such a matrix exists. More...
 
bool hasSameRowSpace (const Matrix &a, const Matrix &b)
 Returns true if a and b have the same row space. More...
 
bool hasSameColSpace (const Matrix &a, const Matrix &b)
 Returns true if a and b have the same column space. More...
 
mpq_class determinant (const Matrix &mat)
 Returns the determinant of mat. More...
 
bool isParallelogram (const Matrix &mat)
 Returns true if the rows of mat are the (4) vertices of a parallelogram. More...
 
mpq_class getParallelogramAreaSq (const Matrix &mat)
 Returns the square of the area of the parallelogram whose vertices are the 4 rows of mat. More...
 

Function Documentation

◆ addMultiplyRow()

void addMultiplyRow ( Matrix mat,
size_t  resultRow,
size_t  sourceRow,
const mpq_class &  mult 
)

Adds mult times row sourceRow to row resultRow of mat.

Definition at line 147 of file Matrix.cpp.

◆ copyRow()

void copyRow ( Matrix target,
size_t  targetRow,
const Matrix source,
size_t  sourceRow 
)

Copies row sourceRow from source to row targetRow of target.

source and target must have the same number of columns.

Definition at line 246 of file Matrix.cpp.

◆ determinant()

mpq_class determinant ( const Matrix mat)

Returns the determinant of mat.

Definition at line 410 of file Matrix.cpp.

◆ getParallelogramAreaSq()

mpq_class getParallelogramAreaSq ( const Matrix mat)

Returns the square of the area of the parallelogram whose vertices are the 4 rows of mat.

Mat must be a parallelogram. The square of the are is integer if the entries of mat are integer and otherwise it is rational. The are itself can be an irrational number.

Definition at line 456 of file Matrix.cpp.

◆ hasSameColSpace()

bool hasSameColSpace ( const Matrix a,
const Matrix b 
)

Returns true if a and b have the same column space.

Definition at line 400 of file Matrix.cpp.

◆ hasSameRowSpace()

bool hasSameRowSpace ( const Matrix a,
const Matrix b 
)

Returns true if a and b have the same row space.

Definition at line 390 of file Matrix.cpp.

◆ inverse()

bool inverse ( Matrix inv,
const Matrix mat 
)

Sets inv to the inverse of mat.

mat must be a square matrix. Returns true if mat is invertible. Returns false and leaves inv in some valid but unspecified state if mat is not invertible.

Definition at line 257 of file Matrix.cpp.

◆ isParallelogram()

bool isParallelogram ( const Matrix mat)

Returns true if the rows of mat are the (4) vertices of a parallelogram.

Definition at line 452 of file Matrix.cpp.

◆ matrixRank()

size_t matrixRank ( const Matrix matParam)

Returns the rank of mat.

Definition at line 276 of file Matrix.cpp.

◆ multiplyRow()

void multiplyRow ( Matrix mat,
size_t  row,
const mpq_class &  mult 
)

Multiplies row row with mult.

Definition at line 156 of file Matrix.cpp.

◆ nullSpace()

void nullSpace ( Matrix basis,
const Matrix matParam 
)

Sets the columns of basis to a basis of the null space of mat.

Definition at line 296 of file Matrix.cpp.

◆ operator<<()

ostream& operator<< ( ostream &  out,
const Matrix mat 
)

Definition at line 94 of file Matrix.cpp.

◆ operator==()

bool operator== ( const Matrix a,
const Matrix b 
)

Definition at line 82 of file Matrix.cpp.

◆ print() [1/2]

void print ( ColumnPrinter pr,
const Matrix mat 
)

Definition at line 107 of file Matrix.cpp.

◆ print() [2/2]

void print ( FILE *  file,
const Matrix mat 
)

Definition at line 101 of file Matrix.cpp.

◆ product()

void product ( Matrix prod,
const Matrix a,
const Matrix b 
)

Sets prod to a * b.

Definition at line 116 of file Matrix.cpp.

◆ rowReduce()

bool rowReduce ( Matrix mat)

Reduces mat to row-echelon form, i.e.

make it upper triangular. This does not include making the pivot entries

  1. Returns true if the permutation made of the rows is odd.

Definition at line 169 of file Matrix.cpp.

◆ rowReduceFully()

void rowReduceFully ( Matrix mat)

Reduces mat to reduced row-echelon form, i.e.

a row-echelon matrix such that no column contains two non-zero entries and all entries are zero or one.

Todo:
: do back substitution instead.

Definition at line 200 of file Matrix.cpp.

◆ solve()

bool solve ( Matrix sol,
const Matrix lhs,
const Matrix rhs 
)

Sets sol to some matrix such that lhs*sol=rhs and returns true if such a matrix exists.

Otherwise returns false and does not change sol.

Definition at line 348 of file Matrix.cpp.

◆ subMatrix()

void subMatrix ( Matrix sub,
const Matrix mat,
size_t  rowBegin,
size_t  rowEnd,
size_t  colBegin,
size_t  colEnd 
)

Sets sub to the sub-matrix of mat with rows in the interval [rowBegin, rowEnd) and columns in the interval [colBegin, colEnd).

Definition at line 225 of file Matrix.cpp.

◆ swapRows()

void swapRows ( Matrix mat,
size_t  row1,
size_t  row2 
)

Swaps row row1 and row row2 of mat.

Definition at line 161 of file Matrix.cpp.

◆ transpose() [1/2]

void transpose ( Matrix mat)

Transpose mat inplace.

Definition at line 141 of file Matrix.cpp.

◆ transpose() [2/2]

void transpose ( Matrix trans,
const Matrix mat 
)

Sets trans to the transpose of mat.

Definition at line 129 of file Matrix.cpp.