ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Data Structures | Typedefs | Functions
matrix.h File Reference

matrix functions More...

Go to the source code of this file.

Data Structures

struct  _mat
 

Typedefs

typedef struct _mat mat_t
 

Functions

MEMSPACE int TestSquare (mat_t MatA)
 Credits: https://www.cs.rochester.edu/~brown/Crypto/assts/projects/adj.html. More...
 
MEMSPACE mat_t MatAlloc (int rows, int cols)
 Allocate a matrix. More...
 
MEMSPACE mat_t MatAllocSQ (int size)
 Allocate a matrix. More...
 
MEMSPACE void MatFree (mat_t matF)
 Free a matrix. More...
 
MEMSPACE mat_t MatLoad (void *V, int rows, int cols)
 Load a matrix. More...
 
MEMSPACE mat_t MatLoadSQ (void *V, int size)
 Load a square matrix. More...
 
MEMSPACE void MatPrint (mat_t matrix)
 Print a matrix. More...
 
MEMSPACE mat_t DeleteRowCol (mat_t MatA, int row, int col)
 Create smaller matrix by deleatting specified row and colume Used by Minor and Cofactor. More...
 
MEMSPACE mat_t Transpose (mat_t MatA)
 Transpose matrix. More...
 
MEMSPACE float Minor (mat_t MatA, int row, int col)
 Compute determinate of the minor submatrix Minor submatrix has one less row and column as a result. More...
 
MEMSPACE float Cofactor (mat_t MatA, int row, int col)
 Cofactor is determinate of minor submatrix * (-1)exp(row+col) Minor submatrix has one less row and column as a result. More...
 
MEMSPACE mat_t Adjugate (mat_t MatA)
 Adjugate is transpose of cofactor matrix of A. More...
 
MEMSPACE float Determinant (mat_t MatA)
 Determinant by recursion using Cofactors. More...
 
MEMSPACE mat_t Invert (mat_t MatA)
 Calculate Matrix Inverse. More...
 
MEMSPACE mat_t PseudoInvert (mat_t MatA)
 Calculate Pseudo Matrix Inverse Used for least square fitting of non square matrix with excess solutions Pseudo Inverse matrix(A) = 1/(AT × A) × AT. More...
 
MEMSPACE mat_t MatMul (mat_t MatA, mat_t MatB)
 Multiply two matrix. More...
 
MEMSPACE mat_t MatRead (char *name)
 Read a matrix. More...
 
MEMSPACE int MatWrite (char *name, mat_t MatW)
 Write a matrix. More...
 

Detailed Description

matrix functions

Copyright © 2016 Mike Gore, GPL License
You are free to use this code under the terms of GPL
please retain a copy of this notice in any code you use it in.

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file matrix.h.

Typedef Documentation

typedef struct _mat mat_t

Function Documentation

MEMSPACE mat_t Adjugate ( mat_t  MatA)

Adjugate is transpose of cofactor matrix of A.

See also
https://en.wikipedia.org/wiki/Adjugate_matrix
Parameters
[in]MatAmatrix A
Returns
Adjugate or A

Definition at line 325 of file matrix.c.

Referenced by Invert(), and MatWrite().

MEMSPACE float Cofactor ( mat_t  MatA,
int  row,
int  col 
)

Cofactor is determinate of minor submatrix * (-1)exp(row+col) Minor submatrix has one less row and column as a result.

See also
https://en.wikipedia.org/wiki/Cofactor
Parameters
[in]MatAmatrix A
[in]rowrow to delete
[in]colcol to delete
Returns
Determinate * (-1)exp(row + col)

Definition at line 310 of file matrix.c.

Referenced by Adjugate(), and Determinant().

MEMSPACE mat_t DeleteRowCol ( mat_t  MatA,
int  row,
int  col 
)

Create smaller matrix by deleatting specified row and colume Used by Minor and Cofactor.

Parameters
[in]MatAmatrix A - row and col must be >= 2
[in]rowrow to delete
[in]colcol to delete
Returns
submatrix

Definition at line 212 of file matrix.c.

Referenced by Minor().

MEMSPACE float Determinant ( mat_t  MatA)

Determinant by recursion using Cofactors.

See also
https://en.wikipedia.org/wiki/Determinant
Parameters
[in]MatAsquare matrix A
Returns
Determinant or 0

Definition at line 350 of file matrix.c.

Referenced by Invert(), and Minor().

MEMSPACE mat_t Invert ( mat_t  MatA)

Calculate Matrix Inverse.

See also
https://en.wikipedia.org/wiki/Invertible_matrix Method used: Adjugate(MatA) / Det(MatA)
Parameters
[in]MatAsquare matrix A input
Returns
Inverse of MatA or error

Definition at line 399 of file matrix.c.

Referenced by MatWrite(), and PseudoInvert().

MEMSPACE mat_t MatAlloc ( int  rows,
int  cols 
)

Allocate a matrix.

Parameters
[in]sizesize of square matrix to allocate
Returns
float **

Definition at line 48 of file matrix.c.

Referenced by Adjugate(), DeleteRowCol(), MatAllocSQ(), MatLoad(), MatMul(), MatRead(), and Transpose().

MEMSPACE mat_t MatAllocSQ ( int  size)

Allocate a matrix.

Parameters
[in]sizesize of square matrix to allocate
Returns
float **

Definition at line 105 of file matrix.c.

MEMSPACE void MatFree ( mat_t  matF)

Free a matrix.

Parameters
[in]**MatMatrix to free

Definition at line 116 of file matrix.c.

Referenced by MatAlloc(), MatRead(), MatWrite(), Minor(), and PseudoInvert().

MEMSPACE mat_t MatLoad ( void *  V,
int  rows,
int  cols 
)

Load a matrix.

Parameters
[in]*Vmatrix data
[in]sizesize of square matrix

Definition at line 152 of file matrix.c.

Referenced by MatLoadSQ(), and MatWrite().

MEMSPACE mat_t MatLoadSQ ( void *  V,
int  size 
)

Load a square matrix.

Parameters
[in]*Vsquare matrix data
[in]sizesize of square matrix

Definition at line 176 of file matrix.c.

Referenced by MatWrite().

MEMSPACE mat_t MatMul ( mat_t  MatA,
mat_t  MatB 
)

Multiply two matrix.

See also
https://en.wikipedia.org/wiki/Matrix_multiplication_algorithm C = AB, A is n × m matrix, B is m × p matrix C result n × p matrix (dimensions row size of A, column size of B) Cij = Sum(k=1 .. m) Aik * Bik
Parameters
[in]MatAmatrix A
[in]MatBmatrix B
Returns
MatA * MatB Result dimensions is (row size of A, column size of B)

Definition at line 490 of file matrix.c.

Referenced by MatWrite(), and PseudoInvert().

MEMSPACE void MatPrint ( mat_t  matrix)

Print a matrix.

Parameters
[in]MatMatrix to print

Definition at line 187 of file matrix.c.

Referenced by Invert(), and MatWrite().

MEMSPACE mat_t MatRead ( char *  name)

Read a matrix.

Parameters
[in]*namematrix data
Returns
mat_t matrix data Note: on error rows and cols = 0, data = NULL;

Definition at line 527 of file matrix.c.

Referenced by setup().

MEMSPACE int MatWrite ( char *  name,
mat_t  MatW 
)

Write a matrix.

Parameters
[in]*namematrix data
[in]MatWMatrix
Returns
status 1 = success, 0 = fail

Definition at line 605 of file matrix.c.

Referenced by user_tests().

MEMSPACE float Minor ( mat_t  MatA,
int  row,
int  col 
)

Compute determinate of the minor submatrix Minor submatrix has one less row and column as a result.

See also
https://en.wikipedia.org/wiki/Minor_(linear_algebra)
Parameters
[in]MatAmatrix A
[in]rowrow to delete
[in]colcol to delete
Returns
Determinate

Definition at line 291 of file matrix.c.

Referenced by Cofactor().

MEMSPACE mat_t PseudoInvert ( mat_t  MatA)

Calculate Pseudo Matrix Inverse Used for least square fitting of non square matrix with excess solutions Pseudo Inverse matrix(A) = 1/(AT × A) × AT.

Parameters
[in]MatAmatrix A input - does not have to be square
Returns
Pseudo Inverse of MatA or error

Definition at line 456 of file matrix.c.

Referenced by MatWrite().

MEMSPACE int TestSquare ( mat_t  MatA)

Credits: https://www.cs.rochester.edu/~brown/Crypto/assts/projects/adj.html.

Author
Paul Bourke 2002 Test is a matrix is square
Parameters
[in]MatAmatrix A
Returns
1 if ssquare, 0 if not

Definition at line 37 of file matrix.c.

MEMSPACE mat_t Transpose ( mat_t  MatA)

Transpose matrix.

Parameters
[in]MatAmatrix A
Returns
Transpose matrix

Definition at line 263 of file matrix.c.

Referenced by PseudoInvert().