Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
mpower.c File Reference
#include "mpower.h"
#include "rt_nonfinite.h"
#include <math.h>
#include <string.h>
Include dependency graph for mpower.c:

Go to the source code of this file.

Functions

void mpower (const double a[9], double c[9])
 Calculates the inverse of a 3x3 matrix.
 

Function Documentation

◆ mpower()

void mpower ( const double  a[9],
double  c[9] 
)

Calculates the inverse of a 3x3 matrix.

Parameters
[in]aA 9-element array representing the input 3x3 matrix (row-major).
[out]cA 9-element array where the resulting inverse matrix will be stored.
Returns
None
Warning
This function does not check if the matrix is invertible (i.e., if its determinant is zero). Providing a singular matrix may result in undefined behavior or NaNs in the output.

Definition at line 24 of file mpower.c.

25{
26 double x[9];
27 double absx11;
28 double absx21;
29 double absx31;
30 int p1;
31 int p2;
32 int p3;
33 memcpy(&x[0], &a[0], 9U * sizeof(double));
34 p1 = 0;
35 p2 = 3;
36 p3 = 6;
37 absx11 = fabs(a[0]);
38 absx21 = fabs(a[1]);
39 absx31 = fabs(a[2]);
40 if ((absx21 > absx11) && (absx21 > absx31)) {
41 p1 = 3;
42 p2 = 0;
43 x[0] = a[1];
44 x[1] = a[0];
45 x[3] = a[4];
46 x[4] = a[3];
47 x[6] = a[7];
48 x[7] = a[6];
49 } else if (absx31 > absx11) {
50 p1 = 6;
51 p3 = 0;
52 x[0] = a[2];
53 x[2] = a[0];
54 x[3] = a[5];
55 x[5] = a[3];
56 x[6] = a[8];
57 x[8] = a[6];
58 }
59 x[1] /= x[0];
60 x[2] /= x[0];
61 x[4] -= x[1] * x[3];
62 x[5] -= x[2] * x[3];
63 x[7] -= x[1] * x[6];
64 x[8] -= x[2] * x[6];
65 if (fabs(x[5]) > fabs(x[4])) {
66 int itmp;
67 itmp = p2;
68 p2 = p3;
69 p3 = itmp;
70 absx11 = x[1];
71 x[1] = x[2];
72 x[2] = absx11;
73 absx11 = x[4];
74 x[4] = x[5];
75 x[5] = absx11;
76 absx11 = x[7];
77 x[7] = x[8];
78 x[8] = absx11;
79 }
80 x[5] /= x[4];
81 x[8] -= x[5] * x[7];
82 absx11 = (x[1] * x[5] - x[2]) / x[8];
83 absx21 = -(x[1] + x[7] * absx11) / x[4];
84 c[p1] = ((1.0 - x[3] * absx21) - x[6] * absx11) / x[0];
85 c[p1 + 1] = absx21;
86 c[p1 + 2] = absx11;
87 absx11 = -x[5] / x[8];
88 absx21 = (1.0 - x[7] * absx11) / x[4];
89 c[p2] = -(x[3] * absx21 + x[6] * absx11) / x[0];
90 c[p2 + 1] = absx21;
91 c[p2 + 2] = absx11;
92 absx11 = 1.0 / x[8];
93 absx21 = -x[7] * absx11 / x[4];
94 c[p3] = -(x[3] * absx21 + x[6] * absx11) / x[0];
95 c[p3 + 1] = absx21;
96 c[p3 + 2] = absx11;
97}

Referenced by mekf().

Here is the caller graph for this function: