ISSDK  1.7
IoT Sensing Software Development Kit
matrix.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*! \file matrix.h
36  \brief Matrix manipulation functions
37 
38  Contains functions for basic manipulation of 3x3 matrices
39 */
40 
41 #ifndef MATRIX_H
42 #define MATRIX_H
43 
44 // function prototypes
45 
46 /// function sets the 3x3 matrix A to the identity matrix
47 void f3x3matrixAeqI(
48  float A[][3]
49 );
50 /// function sets 3x3 matrix A to 3x3 matrix B
51 void f3x3matrixAeqB(
52  float A[][3],
53  float B[][3]
54 );
55 /// function sets the matrix A to the identity matrix
56 void fmatrixAeqI(
57  float *A[], ///< pointer to the matrix
58  int16 rc ///< dimension of the matrix
59 );
60 /// function sets every entry in the 3x3 matrix A to a constant scalar
62  float A[][3],
63  float Scalar
64 );
65 /// function directly calculates the symmetric inverse of a symmetric 3x3 matrix
66 /// only the on and above diagonal terms in B are used and need to be specified
68  float A[][3],
69  float B[][3]
70 );
71 /// function multiplies all elements of 3x3 matrix A by the specified scalar
73  float A[][3],
74  float Scalar
75 );
76 /// function negates all elements of 3x3 matrix A
78  float A[][3]
79 );
80 /// function calculates the determinant of a 3x3 matrix
81 float f3x3matrixDetA(
82  float A[][3]
83 );
84 /// function computes all eigenvalues and eigenvectors of a real symmetric matrix A[0..n-1][0..n-1]
85 /// stored in the top left of a 10x10 array A[10][10]
86 void fEigenCompute10(
87  float A[][10], ///< real symmetric matrix A[0..n-1][0..n-1]
88  float eigval[], ///< eigval[0..n-1] returns the eigenvalues of A[][].
89  float eigvec[][10], ///< eigvec[0..n-1][0..n-1] returns the normalized eigenvectors of A[][]
90  int8 n ///< n can vary up to and including 10 but the matrices A and eigvec must have 10 columns.
91 );
92 /// function computes all eigenvalues and eigenvectors of a real symmetric matrix A[0..n-1][0..n-1]
93 /// stored in the top left of a 4x4 array A[4][4]
94 /// A[][] is changed on output.
95 /// The eigenvectors are not sorted by value.
96 /// This function is identical to eigencompute10 except for the workaround for 4x4 matrices since C cannot
97 /// handle functions accepting matrices with variable numbers of columns.
98 void fEigenCompute4(
99  float A[][4],
100  float eigval[], ///< eigval[0..n-1] returns the eigenvalues of A[][].
101  float eigvec[][4], ///< eigvec[0..n-1][0..n-1] returns the normalized eigenvectors of A[][]
102  int8 n ///< n can vary up to and including 4 but the matrices A and eigvec must have 4 columns.
103 );
104 void fComputeEigSlice(
105  float fmatA[10][10],
106  float fmatB[10][10],
107  float fvecA[10],
108  int8 i,
109  int8 j,
110  int8 iMatrixSize
111 );
112 /// function uses Gauss-Jordan elimination to compute the inverse of matrix A in situ
113 /// on exit, A is replaced with its inverse
114 void fmatrixAeqInvA(
115  float *A[],
116  int8 iColInd[],
117  int8 iRowInd[],
118  int8 iPivot[],
119  int8 isize,
120  int8* pierror
121 );
122 /// function rotates 3x1 vector u onto 3x1 vector using 3x3 rotation matrix fR.
123 /// the rotation is applied in the inverse direction if itranpose is true
124 void fveqRu(
125  float fv[], ///< 3x1 output vector
126  float fR[][3], ///< rotation matrix
127  float fu[], ///< 3x1 input vector
128  int8 itranspose ///< true if inverse direction desired
129 );
130 /// function multiplies the 3x1 vector V by a 3x3 matrix A
131 void fVeq3x3AxV(
132  float V[3], ///< used for both input and output
133  float A[][3]
134 );
135 
136 #endif // #ifndef MATRIX_H
void fEigenCompute4(float A[][4], float eigval[], float eigvec[][4], int8 n)
Definition: matrix.c:415
float f3x3matrixDetA(float A[][3])
function calculates the determinant of a 3x3 matrix
Definition: matrix.c:217
void fVeq3x3AxV(float V[3], float A[][3])
function multiplies the 3x1 vector V by a 3x3 matrix A
Definition: matrix.c:879
#define B
Definition: status.c:56
void f3x3matrixAeqScalar(float A[][3], float Scalar)
function sets every entry in the 3x3 matrix A to a constant scalar
Definition: matrix.c:117
void f3x3matrixAeqI(float A[][3])
function sets the 3x3 matrix A to the identity matrix
Definition: matrix.c:53
void f3x3matrixAeqInvSymB(float A[][3], float B[][3])
Definition: matrix.c:176
void f3x3matrixAeqB(float A[][3], float B[][3])
function sets 3x3 matrix A to 3x3 matrix B
Definition: matrix.c:74
void f3x3matrixAeqMinusA(float A[][3])
function negates all elements of 3x3 matrix A
Definition: matrix.c:155
void fveqRu(float fv[], float fR[][3], float fu[], int8 itranspose)
Definition: matrix.c:828
void fmatrixAeqInvA(float *A[], int8 iColInd[], int8 iRowInd[], int8 iPivot[], int8 isize, int8 *pierror)
Definition: matrix.c:674
void f3x3matrixAeqAxScalar(float A[][3], float Scalar)
function multiplies all elements of 3x3 matrix A by the specified scalar
Definition: matrix.c:136
void fmatrixAeqI(float *A[], int16 rc)
function sets the matrix A to the identity matrix
Definition: matrix.c:95
void fComputeEigSlice(float fmatA[10][10], float fmatB[10][10], float fvecA[10], int8 i, int8 j, int8 iMatrixSize)
Definition: matrix.c:580
void fEigenCompute10(float A[][10], float eigval[], float eigvec[][10], int8 n)
Definition: matrix.c:242
int16_t int16
Definition: sensor_fusion.h:66
int8_t int8
Definition: sensor_fusion.h:65