matrix module  1.00.00
www.protokollkonverter.de
matrix operations

Data Structures

struct  _MATRIX
 internal description of a matrix More...
 

Macros

#define VECTOR_STANDARD_DIMENSION   3
 standard dimension for vectors, normal coordination system More...
 

Typedefs

typedef struct _MATRIXMATRIX
 instance pointer of a matrix More...
 
typedef struct _MATRIXVECTOR
 instance pointer of a vector More...
 
typedef double MATRIX_VALUE
 type of supported value More...
 
typedef struct _MATRIX TMATRIX
 dummy to avoid compiler warning More...
 

Functions

void matrixPrint (MATRIX A)
 print matrix More...
 
MATRIX matrixNew (const size_t rows, const size_t columns)
 create a new matrix More...
 
MATRIX matrixNewUnit (const size_t dimension)
 create a new unit matrix More...
 
void matrixDelete (MATRIX *A)
 free memory allocated by matrixNew More...
 
bool matrixGetDimension (MATRIX A, size_t *rows, size_t *columns)
 get dimensions of matrix More...
 
bool matrixEquals (MATRIX A, MATRIX B)
 compare two matrices More...
 
bool matrixSetElement (MATRIX A, const size_t row, const size_t column, const MATRIX_VALUE value)
 set one element in matrix More...
 
bool matrixSetRow (MATRIX A, const size_t row, const MATRIX_VALUE values[], const size_t valuesCount)
 set one row in matrix More...
 
bool matrixSetColumn (MATRIX A, const size_t column, const MATRIX_VALUE values[], const size_t valuesCount)
 set one column in matrix More...
 
bool matrixSet (MATRIX A, const MATRIX_VALUE values[], const size_t valuesCount)
 set values of matrix More...
 
bool matrixGetElement (MATRIX A, const size_t row, const size_t column, MATRIX_VALUE *value)
 get one element in matrix More...
 
bool matrixGetRow (MATRIX A, const size_t row, MATRIX_VALUE values[], size_t *valuesCount)
 get one row in matrix More...
 
bool matrixGetColumn (MATRIX A, const size_t column, MATRIX_VALUE values[], size_t *valuesCount)
 get one column in matrix More...
 
bool matrixGet (MATRIX A, MATRIX_VALUE values[], size_t *valuesCount)
 get values of matrix More...
 
MATRIX matrixAddition (MATRIX A, MATRIX B)
 addition of two matrices More...
 
MATRIX matrixSubstraction (MATRIX A, MATRIX B)
 subtraction of two matrices More...
 
MATRIX matrixMultiplication (MATRIX A, MATRIX B)
 multiplication of two matrices More...
 
MATRIX matrixMultiplicationScalar (MATRIX A, MATRIX_VALUE scalar)
 multiplication of matrix with scalar More...
 
MATRIX matrixTransposition (MATRIX A)
 transposition of matrix More...
 
MATRIX matrixInverse (MATRIX A)
 calculate inverse of matrix More...
 
bool matrixDeterminant (MATRIX A, MATRIX_VALUE *determinant)
 calculate determinant of matrix More...
 
MATRIX matrixClone (MATRIX A)
 clone a matrix More...
 
VECTOR matrixSolve (MATRIX A, VECTOR y)
 solve matrix A with result vector y More...
 
static MATRIX matrixSubDeterminant (MATRIX A, const size_t row, const size_t column)
 create a sub matrix More...
 

Detailed Description

Macro Definition Documentation

#define VECTOR_STANDARD_DIMENSION   3

standard dimension for vectors, normal coordination system

Examples:
testMatrix.cpp.

Typedef Documentation

instance pointer of a matrix

instance pointer of a vector

The pointer is the same as MATRIX. It's for good programming style.

type of supported value

The type declares type of value to calculate with.

dummy to avoid compiler warning

Function Documentation

void matrixPrint ( MATRIX  A)

print matrix

Function prints matrix to stdout by puts and printf.

For example \(\begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}\) will be printed as

1 +-
2 | 1.000 0.000 0.000
3 | 0.000 1.000 0.000
4 | 0.000 0.000 1.000
5 +-
Parameters
[in]Amatrix to print
Examples:
testMatrix.cpp.

Here is the call graph for this function:

MATRIX matrixNew ( const size_t  rows,
const size_t  columns 
)

create a new matrix

Function allocates memory for a new matrix of given dimensions. All elements are set to 0.

See also
matrixDelete
Parameters
[in]rowsrows of matrix A to create
[in]columnscolumns of matrix A to create
Returns
new matrix
NULL on memory allocation error
Examples:
testMatrix.cpp.

Here is the caller graph for this function:

MATRIX matrixNewUnit ( const size_t  dimension)

create a new unit matrix

Function allocates memory for a new matrix of and initialize values.

For example matrixNewUnit(3) will create a matrix like

\[ \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} \]

See also
matrixDelete
Parameters
[in]dimensiondimension of rows and columns of matrix A to create
Returns
new matrix
NULL on parameter or memory allocation error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

void matrixDelete ( MATRIX A)

free memory allocated by matrixNew

Function frees memory of matrix created by matrixNew or matrixNewUnit. The matrix pointer A will be set to NULL.

Parameters
[in,out]Apointer to matrix do delete
Examples:
testMatrix.cpp.

Here is the caller graph for this function:

bool matrixGetDimension ( MATRIX  A,
size_t *  rows,
size_t *  columns 
)

get dimensions of matrix

Function inserts dimensions of matrix in rows an columns if pointers are different to NULL.

Parameters
[out]rowsaddress of variable rows to insert count of rows of matrix, can be NULL if only columns are requested
[out]columnsaddress of variable columns to insert count of columns of matrix, can be NULL if only rows are requested
Returns
true on success
false on parameter error (A is NULL)
Examples:
testMatrix.cpp.

Here is the caller graph for this function:

bool matrixEquals ( MATRIX  A,
MATRIX  B 
)

compare two matrices

Function compares matrices. Matrices are equal if they have the same dimensions and all elements are equal.

Parameters
[in]Amatrix to compare with matrix B
[in]Bmatrix to compare with matrix A
Returns
true if matrices are equal
false if matrices are not equal or parameter error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

bool matrixSetElement ( MATRIX  A,
const size_t  row,
const size_t  column,
const MATRIX_VALUE  value 
)

set one element in matrix

Function sets the value of one element in matrix. Rows are count from 0..(rows of matrix - 1) and columns from 0..(columns of matrix - 1).

Parameters
[in]Amatrix to set value in
[in]rowrow of element
[in]columncolumn of element
[in]valuevalue to set to element
Returns
true on success
false on parameter error
Examples:
testMatrix.cpp.

Here is the caller graph for this function:

bool matrixSetRow ( MATRIX  A,
const size_t  row,
const MATRIX_VALUE  values[],
const size_t  valuesCount 
)

set one row in matrix

Function sets values of one row in matrix. Rows are count from 0..(rows of matrix - 1). valuesCount must be equal to columns of matrix.

Parameters
[in]Amatrix to set value in
[in]rowrow to set
[in]valuesvalues to set
[in]valuesCountcount of values to set
Returns
true on success
false on parameter error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

bool matrixSetColumn ( MATRIX  A,
const size_t  column,
const MATRIX_VALUE  values[],
const size_t  valuesCount 
)

set one column in matrix

Function sets values of one column in matrix. Columns are count from 0..(columns of matrix - 1).

Note
valuesCount must be equal to rows of matrix.
Parameters
[in]Amatrix to set value in
[in]columncolumn to set
[in]valuesvalues to set
[in]valuesCountcount of values to set
Returns
true on success
false on parameter error

Here is the call graph for this function:

Here is the caller graph for this function:

bool matrixSet ( MATRIX  A,
const MATRIX_VALUE  values[],
const size_t  valuesCount 
)

set values of matrix

Function sets all values of matrix. Columns are count from 0..(columns of matrix - 1).

Note
valuesCount must be equal to rows * columns of matrix.

values must be sorted in following way:

\(\lbrace a_{0,0}, a_{0,1}, .. a_{0,(columns-1)}, a_{1,0}, a_{1,1}, ..., a_{(rows-1),(columns-1)} \rbrace\)

Parameters
[in]Amatrix to set value in
[in]valuesvalues to set
[in]valuesCountcount of values to set
Returns
true on success
false on parameter error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

bool matrixGetElement ( MATRIX  A,
const size_t  row,
const size_t  column,
MATRIX_VALUE value 
)

get one element in matrix

Function gets the value of one element in matrix. Rows are count from 0..(rows of matrix - 1) and columns from 0..(columns of matrix - 1).

Parameters
[in]Amatrix to get value from
[in]rowrow of element
[in]columncolumn of element
[out]valuepointer to value to set value of element in
Returns
true on success
false on parameter error
Examples:
testMatrix.cpp.

Here is the caller graph for this function:

bool matrixGetRow ( MATRIX  A,
const size_t  row,
MATRIX_VALUE  values[],
size_t *  valuesCount 
)

get one row in matrix

Function gets values of one row in matrix. Rows are count from 0..(rows of matrix - 1).

Note
valuesCount must be greater or equal to columns of matrix.
Parameters
[in]Amatrix to get values from
[in]rowrow to get
[out]valuespointer to values to copy value of elements to
[in,out]valuesCountcount of values in array
contains afterwards count of copied values
Returns
true on success
false on parameter error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

bool matrixGetColumn ( MATRIX  A,
const size_t  column,
MATRIX_VALUE  values[],
size_t *  valuesCount 
)

get one column in matrix

Function gets values of one column in matrix. Columns are count from 0..(columns of matrix - 1).

Note
valuesCount must be greater or equal to rows of matrix.
Parameters
[in]Amatrix to get values from
[in]columncolumn to get
[out]valuespointer to values to copy value of elements to
[in,out]valuesCountcount of values in array
contains afterwards count of copied values
Returns
true on success
false on parameter error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool matrixGet ( MATRIX  A,
MATRIX_VALUE  values[],
size_t *  valuesCount 
)

get values of matrix

Function gets all values of matrix. Columns are count from 0..(columns of matrix - 1).

Note
valuesCount must be greater or equal to rows * columns of matrix.

values are sorted in following way:

\(\lbrace a_{0,0}, a_{0,1}, .. a_{0,(columns-1)}, a_{1,0}, a_{1,1}, ..., a_{(rows-1),(columns-1)} \rbrace\)

Parameters
[in]Amatrix to get values from
[out]valuespointer to values to copy value of elements to
[in,out]valuesCountcount of values in array
contains afterwards count of copied values
Returns
true on success
false on parameter error

Here is the call graph for this function:

MATRIX matrixAddition ( MATRIX  A,
MATRIX  B 
)

addition of two matrices

Function adds two matrices.

Note
Matrices must be of the same dimension.
Parameters
[in]Amatrix 1 to add
[in]Bmatrix 2 to add
Returns
new matrix with added values
NULL on parameter or memory allocation error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

MATRIX matrixSubstraction ( MATRIX  A,
MATRIX  B 
)

subtraction of two matrices

Function subtract matrix B form A.

Note
Matrices must be of the same dimension.
Parameters
[in]Amatrix to subtract from
[in]Bmatrix to subtract from A
Returns
new matrix with subtracted values
NULL on parameter or memory allocation error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

MATRIX matrixMultiplication ( MATRIX  A,
MATRIX  B 
)

multiplication of two matrices

Function multiplies matrix A and B.

Note
The count of columns of matrix A must be equal to count of rows of matrix B.
Parameters
[in]Amatrix to multiply
[in]Bmatrix to multiply to A
Returns
new matrix with multiplied values
NULL on parameter or memory allocation error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

MATRIX matrixMultiplicationScalar ( MATRIX  A,
MATRIX_VALUE  scalar 
)

multiplication of matrix with scalar

Function multiplies matrix A with scalar value.

Parameters
[in]Amatrix to multiply
[in]scalarvalue to multiply matrix A with
Returns
new matrix with multiplied values
NULL on parameter or memory allocation error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

MATRIX matrixTransposition ( MATRIX  A)

transposition of matrix

Function transpose matrix.

Parameters
[in]Amatrix to transpose
Returns
new matrix with transposed rows an columns
NULL on parameter or memory allocation error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

MATRIX matrixInverse ( MATRIX  A)

calculate inverse of matrix

Function inverses matrix by recursive Leipniz.

Parameters
[in]Amatrix to inverse
Returns
new inversed matrix
NULL on det(matrix) == 0 or parameter or memory allocation error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

bool matrixDeterminant ( MATRIX  A,
MATRIX_VALUE determinant 
)

calculate determinant of matrix

Function calculate determinant of matrix by recursive Leipniz.

Parameters
[in]Amatrix to calculate
[out]determinantpointer to value to set determinant of matrix in
Returns
true on success
false on parameter error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

MATRIX matrixClone ( MATRIX  A)

clone a matrix

Function creates a new matrix with the same dimensions and values like given matrix.

Parameters
[in]Amatrix to clone
Returns
new matrix like A
NULL on parameter or memory allocation error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

VECTOR matrixSolve ( MATRIX  A,
VECTOR  y 
)

solve matrix A with result vector y

Function solves system of linear equations by Cramer with determinants by recursive Leipniz.

\[ A * \vec a = \vec y \]

Parameters
[in]Amatrix of a coefficients
[in]yvector with results
Returns
vector a on success
NULL if unsolvable or on parameter error
Examples:
testMatrix.cpp.

Here is the call graph for this function:

static MATRIX matrixSubDeterminant ( MATRIX  A,
const size_t  row,
const size_t  column 
)
static

create a sub matrix

Function creates a sub matrix of matrix A. The sub matrix has dimensions (rows of A) - 1 and (columns of A) - 1. The new matrix contains all elements except the elements of given row and column.

\[ \begin{pmatrix} a_{0,0} & a_{0,1} & a_{0,1} \\ a_{1,0} & a_{1,1} & a_{1,2} \\ a_{2,0} & a_{2,1} & a_{2,2} \end{pmatrix} with \begin{Bmatrix} row := 1 \\ column := 2 \end{Bmatrix} => \begin{vmatrix} a_{0,0} & a_{0,1} \\ a_{2,0} & a_{2,1} \end{vmatrix} \]

Parameters
[in]Amatrix to create a sub matrix from
[in]rowrow of matrix A to ignore
[in]columncolumn of matrix A to ignore
Returns
new matrix
NULL on memory allocation error

Here is the call graph for this function:

Here is the caller graph for this function: