47 for (i = 0; i < n; i++) {
48 for (j = 0; j < (i + 1); j++) {
50 for (k = 0; k < j; k++) {
51 s += o[i][k] * o[j][k];
55 (1.0 / o[j][j] * (in[i][j] - s));
78 float _z[
m][n], _z1[
m][n], _z2[
m][
m];
82 for (i = 0; i <
m; i++)
for (k = 0; k <
m; k++) { q[i][k] = &_q[i][k][0]; }
84 for (k = 0; k < n && k < m - 1; k++) {
85 float e[
m], x[
m], a, b;
89 if (in[k][k] > 0) { a = -a; }
90 for (i = 0; i <
m; i++) {
91 e[i] = (i == k) ? 1 : 0;
92 e[i] = x[i] + a * e[i];
100 for (i = 1; i < n && i < m - 1; i++) {
112 static inline float pythag(
float a,
float b)
118 return (absa * sqrtf(1.0 + (absb / absa) * (absb / absa)));
119 }
else if (absb == 0.0) {
122 return (absb * sqrtf(1.0 + (absa / absb) * (absa / absb)));
150 int flag, i, its, j, jj, k, l, NM;
151 float C, F, H, S, X, Y, Z, tmp;
157 for (i = 0; i < n; ++i) {
164 for (k = i; k <
m; ++k) {
165 Scale = Scale + fabsf(a[k][i]);
168 for (k = i; k <
m; ++k) {
169 a[k][i] = a[k][i] / Scale;
170 S = S + a[k][i] * a[k][i];
180 for (j = l; j < n; ++j) {
182 for (k = i; k <
m; ++k) {
183 S = S + a[k][i] * a[k][j];
186 for (k = i; k <
m; ++k) {
187 a[k][j] = a[k][j] + F * a[k][i];
191 for (k = i; k <
m; ++k) {
192 a[k][i] = Scale * a[k][i];
201 if ((i < m) && (i != (n - 1))) {
202 for (k = l; k < n; ++k) {
203 Scale = Scale + fabsf(a[i][k]);
206 for (k = l; k < n; ++k) {
207 a[i][k] = a[i][k] / Scale;
208 S = S + a[i][k] * a[i][k];
217 for (k = l; k < n; ++k) {
218 rv1[k] = a[i][k] / H;
221 for (j = l; j <
m; ++j) {
223 for (k = l; k < n; ++k) {
224 S = S + a[j][k] * a[i][k];
226 for (k = l; k < n; ++k) {
227 a[j][k] = a[j][k] + S * rv1[k];
231 for (k = l; k < n; ++k) {
232 a[i][k] = Scale * a[i][k];
236 tmp = fabsf(w[i]) + fabsf(rv1[i]);
243 for (i = n - 1; i >= 0; --i) {
246 for (j = l; j < n; ++j) {
247 v[j][i] = (a[i][j] / a[i][l]) / G;
249 for (j = l; j < n; ++j) {
251 for (k = l; k < n; ++k) {
252 S = S + a[i][k] * v[k][j];
254 for (k = l; k < n; ++k) {
255 v[k][j] = v[k][j] + S * v[k][i];
259 for (j = l; j < n; ++j) {
270 for (i = n - 1; i >= 0; --i) {
274 for (j = l; j < n; ++j) {
281 for (j = l; j < n; ++j) {
283 for (k = l; k <
m; ++k) {
284 S = S + a[k][i] * a[k][j];
286 F = (S / a[i][i]) * G;
287 for (k = i; k <
m; ++k) {
288 a[k][j] = a[k][j] + F * a[k][i];
292 for (j = i; j <
m; ++j) {
293 a[j][i] = a[j][i] * G;
296 for (j = i; j <
m; ++j) {
300 a[i][i] = a[i][i] + 1.0;
305 for (k = (n - 1); k >= 0; --k) {
307 for (its = 1; its <= 30; ++its) {
311 for (l = k; l >= 0; --l) {
313 if ((fabsf(rv1[l]) + ANorm) == ANorm) {
316 }
else if ((fabsf(w[NM]) + ANorm) == ANorm) {
325 for (i = l; i <= k; ++i) {
327 if ((fabsf(F) + ANorm) != ANorm) {
335 for (j = 0; j <
m; ++j) {
338 a[j][NM] = (Y * C) + (Z * S);
339 a[j][i] = -(Y * S) + (Z * C);
350 for (j = 0; j < n; ++j) {
367 F = ((Y - Z) * (Y + Z) + (G - H) * (G + H)) / (2.0 * H * Y);
374 F = ((X - Z) * (X + Z) + H * ((Y / (F + tmp)) - H)) / X;
379 for (j = l; j <= NM; ++j) {
390 F = (X * C) + (G * S);
391 G = -(X * S) + (G * C);
394 for (jj = 0; jj < n; ++jj) {
397 v[jj][j] = (X * C) + (Z * S);
398 v[jj][i] = -(X * S) + (Z * C);
410 F = (C * G) + (S * Y);
411 X = -(S * G) + (C * Y);
412 for (jj = 0; jj <
m; ++jj) {
415 a[jj][j] = (Y * C) + (Z * S);
416 a[jj][i] = -(Y * S) + (Z * C);
451 for (k = 0; k < l; k++) {
452 for (j = 0; j < n; j++) {
455 for (i = 0; i <
m; i++) { s += u[i][j] * b[i][k]; }
460 for (j = 0; j < n; j++) {
462 for (jj = 0; jj < n; jj++) { s += v[j][jj] * tmp[jj]; }
void pprz_cholesky_float(float **out, float **in, int n)
Cholesky decomposition.
static void float_mat_transpose(float **a, int n)
transpose square matrix
static float float_vect_norm(const float *a, const int n)
||a||
#define MAKE_MATRIX_PTR(_ptr, _mat, _rows)
Make a pointer to a matrix of _rows lines.
static float pythag(float a, float b)
Some SVD decomposition utility macros and functions.
static void float_mat_copy(float **a, float **b, int m, int n)
a = b
static void float_mat_col(float *o, float **a, int m, int c)
o = c-th column of matrix a[m x n]
static void float_mat_vmul(float **o, float *v, int n)
o = I - v v^T
void pprz_qr_float(float **Q, float **R, float **in, int m, int n)
QR decomposition.
static void float_vect_sdiv(float *o, const float *a, const float s, const int n)
o = a / s
static void float_mat_minor(float **o, float **a, int m, int n, int d)
matrix minor
Paparazzi floating point algebra.
static void float_mat_zero(float **a, int m, int n)
a = 0
void pprz_svd_solve_float(float **x, float **u, float *w, float **v, float **b, int m, int n, int l)
SVD based linear solver.
Matrix decompositions in floating point.
int pprz_svd_float(float **a, float *w, float **v, int m, int n)
SVD decomposition.
static void float_mat_mul(float **o, float **a, float **b, int m, int n, int l)
o = a * b