23#define CORRUPTMATRIX 0.001F
31 for (i = 0; i < 3; i++)
35 for (j = 0; j < 3; j++)
53 for (i = 0; i < 3; i++)
58 for (j = 0; j < 3; j++)
60 *(pAij++) = *(pBij++);
74 for (i = 0; i < rc; i++)
78 for (j = 0; j < rc; j++)
95 for (i = 0; i < 3; i++)
99 for (j = 0; j < 3; j++)
114 for (i = 0; i < 3; i++)
118 for (j = 0; j < 3; j++)
133 for (i = 0; i < 3; i++)
137 for (j = 0; j < 3; j++)
151 float fB11B22mB12B12;
152 float fB12B02mB01B22;
153 float fB01B12mB11B02;
157 fB11B22mB12B12 = B[1][1] * B[2][2] - B[1][2] * B[1][2];
158 fB12B02mB01B22 = B[1][2] * B[0][2] - B[0][1] * B[2][2];
159 fB01B12mB11B02 = B[0][1] * B[1][2] - B[1][1] * B[0][2];
173 A[0][0] = fB11B22mB12B12 * ftmp;
174 A[1][0] = A[0][1] = fB12B02mB01B22 * ftmp;
175 A[2][0] = A[0][2] = fB01B12mB11B02 * ftmp;
176 A[1][1] = (B[0][0] * B[2][2] - B[0][2] * B[0][2]) * ftmp;
177 A[2][1] = A[1][2] = (B[0][2] * B[0][1] - B[0][0] * B[1][2]) * ftmp;
178 A[2][2] = (B[0][0] * B[1][1] - B[0][1] * B[0][1]) * ftmp;
218#define NITERATIONS 15
243 for (i = 0; i < n; i++)
246 for (j = 0; j < n; j++)
267 for (i = 0; i < n - 1; i++)
270 for (j = i + 1; j < n; j++)
273 residue += fabsf(A[i][j]);
281 for (i = 0; i < n - 1; i++)
284 for (j = i + 1; j < n; j++)
287 if (fabsf(A[i][j]) > 0.0F)
290 cot2phi = 0.5F * (eigval[j] - eigval[i]) / (A[i][j]);
293 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
300 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
301 sinphi = tanphi * cosphi;
304 tanhalfphi = sinphi / (1.0F + cosphi);
307 ftmp = tanphi * A[i][j];
320 for (k = 0; k < n; k++)
326 eigvec[k][i] = ftmp - sinphi * (eigvec[k][j] + tanhalfphi * ftmp);
329 eigvec[k][j] = eigvec[k][j] + sinphi * (ftmp - tanhalfphi * eigvec[k][j]);
333 for (k = 0; k <= i - 1; k++)
339 A[k][i] = ftmp - sinphi * (A[k][j] + tanhalfphi * ftmp);
342 A[k][j] = A[k][j] + sinphi * (ftmp - tanhalfphi * A[k][j]);
345 for (k = i + 1; k <= j - 1; k++)
351 A[i][k] = ftmp - sinphi * (A[k][j] + tanhalfphi * ftmp);
354 A[k][j] = A[k][j] + sinphi * (ftmp - tanhalfphi * A[k][j]);
357 for (k = j + 1; k < n; k++)
363 A[i][k] = ftmp - sinphi * (A[j][k] + tanhalfphi * ftmp);
366 A[j][k] = A[j][k] + sinphi * (ftmp - tanhalfphi * A[j][k]);
372 }
while ((residue > 0.0F) && (ctr++ < NITERATIONS));
391#define NITERATIONS 15
416 for (ir = 0; ir < n; ir++)
419 for (ic = 0; ic < n; ic++)
422 eigvec[ir][ic] = 0.0F;
426 eigvec[ir][ir] = 1.0F;
429 eigval[ir] = A[ir][ir];
440 for (ir = 0; ir < n - 1; ir++)
443 for (ic = ir + 1; ic < n; ic++)
446 residue += fabsf(A[ir][ic]);
454 for (ir = 0; ir < n - 1; ir++)
457 for (ic = ir + 1; ic < n; ic++)
460 if (fabsf(A[ir][ic]) > 0.0F)
464 (eigval[ic] - eigval[ir]) /
468 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
475 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
476 sinphi = tanphi * cosphi;
479 tanhalfphi = sinphi / (1.0F + cosphi);
482 ftmp = tanphi * A[ir][ic];
495 for (j = 0; j < n; j++)
498 ftmp = eigvec[j][ir];
501 eigvec[j][ir] = ftmp - sinphi * (eigvec[j][ic] + tanhalfphi * ftmp);
504 eigvec[j][ic] = eigvec[j][ic] + sinphi * (ftmp - tanhalfphi * eigvec[j][ic]);
508 for (j = 0; j <= ir - 1; j++)
514 A[j][ir] = ftmp - sinphi * (A[j][ic] + tanhalfphi * ftmp);
517 A[j][ic] = A[j][ic] + sinphi * (ftmp - tanhalfphi * A[j][ic]);
520 for (j = ir + 1; j <= ic - 1; j++)
526 A[ir][j] = ftmp - sinphi * (A[j][ic] + tanhalfphi * ftmp);
529 A[j][ic] = A[j][ic] + sinphi * (ftmp - tanhalfphi * A[j][ic]);
532 for (j = ic + 1; j < n; j++)
538 A[ir][j] = ftmp - sinphi * (A[ic][j] + tanhalfphi * ftmp);
541 A[ic][j] = A[ic][j] + sinphi * (ftmp - tanhalfphi * A[ic][j]);
547 }
while ((residue > 0.0F) && (ctr++ < NITERATIONS));
553void fComputeEigSlice(
float fmatA[10][10],
float fmatB[10][10],
float fvecA[10],
554 int8_t i, int8_t j, int8_t iMatrixSize)
565 cot2phi = 0.5F * (fvecA[j] - fvecA[i]) / (fmatA[i][j]);
568 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
569 if (cot2phi < 0.0F) tanphi = -tanphi;
572 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
573 sinphi = tanphi * cosphi;
576 tanhalfphi = sinphi / (1.0F + cosphi);
579 ftmp = tanphi * fmatA[i][j];
592 for (k = 0; k < iMatrixSize; k++)
598 fmatB[k][i] = ftmp - sinphi * (fmatB[k][j] + tanhalfphi * ftmp);
601 fmatB[k][j] = fmatB[k][j] + sinphi * (ftmp - tanhalfphi * fmatB[k][j]);
605 for (k = 0; k <= i - 1; k++)
611 fmatA[k][i] = ftmp - sinphi * (fmatA[k][j] + tanhalfphi * ftmp);
614 fmatA[k][j] = fmatA[k][j] + sinphi * (ftmp - tanhalfphi * fmatA[k][j]);
617 for (k = i + 1; k <= j - 1; k++)
623 fmatA[i][k] = ftmp - sinphi * (fmatA[k][j] + tanhalfphi * ftmp);
626 fmatA[k][j] = fmatA[k][j] + sinphi * (ftmp - tanhalfphi * fmatA[k][j]);
629 for (k = j + 1; k < iMatrixSize; k++)
635 fmatA[i][k] = ftmp - sinphi * (fmatA[j][k] + tanhalfphi * ftmp);
638 fmatA[j][k] = fmatA[j][k] + sinphi * (ftmp - tanhalfphi * fmatA[j][k]);
647void fmatrixAeqInvA(
float *A[], int8_t iColInd[], int8_t iRowInd[], int8_t iPivot[],
648 int8_t isize, int8_t *pierror)
663 iPivotRow = iPivotCol = 0;
669 for (j = 0; j < isize; j++)
675 for (i = 0; i < isize; i++)
681 for (j = 0; j < isize; j++)
687 for (k = 0; k < isize; k++)
693 if (fabsf(A[j][k]) >= largest)
698 largest = (float) fabsf(A[iPivotRow][iPivotCol]);
701 else if (iPivot[k] > 1)
716 if (iPivotRow != iPivotCol)
719 for (l = 0; l < isize; l++)
722 ftmp = A[iPivotRow][l];
723 A[iPivotRow][l] = A[iPivotCol][l];
724 A[iPivotCol][l] = ftmp;
729 iRowInd[i] = iPivotRow;
730 iColInd[i] = iPivotCol;
733 if (A[iPivotCol][iPivotCol] == 0.0F)
742 recippiv = 1.0F / A[iPivotCol][iPivotCol];
745 A[iPivotCol][iPivotCol] = 1.0F;
749 for (l = 0; l < isize; l++)
751 if (A[iPivotCol][l] != 0.0F) A[iPivotCol][l] *= recippiv;
755 for (m = 0; m < isize; m++)
760 scaling = A[m][iPivotCol];
763 A[m][iPivotCol] = 0.0F;
766 for (l = 0; l < isize; l++)
768 if ((A[iPivotCol][l] != 0.0F) && (scaling != 0.0F))
769 A[m][l] -= A[iPivotCol][l] * scaling;
776 for (l = isize - 1; l >= 0; l--)
786 for (k = 0; k < isize; k++)
801void fveqRu(
float fv[],
float fR[][3],
float fu[], int8_t itranspose)
void fEigenCompute10(float A[][10], float eigval[], float eigvec[][10], int8_t n)
void f3x3matrixAeqAxScalar(float A[][3], float Scalar)
function multiplies all elements of 3x3 matrix A by the specified scalar
void f3x3matrixAeqI(float A[][3])
function sets the 3x3 matrix A to the identity matrix
float f3x3matrixDetA(float A[][3])
function calculates the determinant of a 3x3 matrix
void f3x3matrixAeqMinusA(float A[][3])
function negates all elements of 3x3 matrix A
void f3x3matrixAeqInvSymB(float A[][3], float B[][3])
void fEigenCompute4(float A[][4], float eigval[], float eigvec[][4], int8_t n)
void fmatrixAeqInvA(float *A[], int8_t iColInd[], int8_t iRowInd[], int8_t iPivot[], int8_t isize, int8_t *pierror)
void f3x3matrixAeqScalar(float A[][3], float Scalar)
function sets every entry in the 3x3 matrix A to a constant scalar
void f3x3matrixAeqB(float A[][3], float B[][3])
function sets 3x3 matrix A to 3x3 matrix B
void fveqRu(float fv[], float fR[][3], float fu[], int8_t itranspose)
void fVeq3x3AxV(float V[3], float A[][3])
function multiplies the 3x1 vector V by a 3x3 matrix A
void fmatrixAeqI(float *A[], int16_t rc)
function sets the matrix A to the identity matrix
Matrix manipulation functions.
The sensor_fusion.h file implements the top level programming interface.
#define CHX
Used to access X-channel entries in various data data structures.
#define CHY
Used to access Y-channel entries in various data data structures.
#define CHZ
Used to access Z-channel entries in various data data structures.