Functions | |
static int | inv2 (const double *a, double *b) |
static int | inv3 (const double *a, double *b) |
static int | inv4 (const double *a, double *b) |
void | matrix_add_sc (u32 n, u32 m, const double *a, const double *b, double gamma, double *c) |
int | matrix_ataati (u32 n, u32 m, const double *a, double *b) |
int | matrix_ataiat (u32 n, u32 m, const double *a, double *b) |
int | matrix_atawati (u32 n, u32 m, const double *a, const double *w, double *b) |
int | matrix_atwaiat (u32 n, u32 m, const double *a, const double *w, double *b) |
void | matrix_copy (u32 n, u32 m, const double *a, double *b) |
int | matrix_inverse (u32 n, const double const *a, double *b) |
void | matrix_multiply (u32 n, u32 m, u32 p, const double *a, const double *b, double *c) |
int | matrix_pseudoinverse (u32 n, u32 m, const double *a, double *b) |
void | matrix_transpose (u32 n, u32 m, const double *a, double *b) |
s32 | qrdecomp (const double *a, u32 rows, u32 cols, double *qt, double *r) |
s32 | qrdecomp_square (const double *a, u32 rows, double *qt, double *r) |
s32 | qrsolve (const double *a, u32 rows, u32 cols, const double *b, double *x) |
void | qtmult (const double *qt, u32 n, const double *b, double *x) |
static void | row_swap (double *a, double *b, u32 size) |
static int | rref (u32 order, u32 cols, double *m) |
void | rsolve (const double *r, u32 rows, u32 cols, const double *b, double *x) |
Routines for working with matrices.
static int inv2 | ( | const double * | a, |
double * | b | ||
) | [inline, static] |
Invert a 2x2 matrix. Calculate the inverse of a 2x2 matrix:
a | The matrix to invert (input) |
b | Where to put the inverse (output) |
Definition at line 384 of file linear_algebra.c.
static int inv3 | ( | const double * | a, |
double * | b | ||
) | [inline, static] |
Invert a 3x3 matrix. Calculate the inverse of a 3x3 matrix:
a | The matrix to invert (input) |
b | Where to put the inverse (output) |
Definition at line 403 of file linear_algebra.c.
static int inv4 | ( | const double * | a, |
double * | b | ||
) | [inline, static] |
Invert a 4x4 matrix. Calculate the inverse of a 4x4 matrix:
a | The matrix to invert (input) |
b | Where to put the inverse (output) |
Definition at line 434 of file linear_algebra.c.
void matrix_add_sc | ( | u32 | n, |
u32 | m, | ||
const double * | a, | ||
const double * | b, | ||
double | gamma, | ||
double * | c | ||
) |
Add a matrix to a scaled matrix. Add two matrices: , where , and are matrices on and is a scalar coefficient.
n | Number of rows in a, b and c |
m | Number of columns in a, b and c |
a | First matrix (unscaled) |
b | Second matrix (will be scaled) |
gamma | Coefficient for second matrix |
c | Output (sum) matrix |
Definition at line 805 of file linear_algebra.c.
int matrix_ataati | ( | u32 | n, |
u32 | m, | ||
const double * | a, | ||
double * | b | ||
) | [inline] |
Compute . Compute , where is a matrix on and is (therefore) a matrix on , for .
n | Number of rows in a and rows and columns in b |
m | Number of columns in a |
a | Input matrix |
b | Output matrix |
Definition at line 762 of file linear_algebra.c.
int matrix_ataiat | ( | u32 | n, |
u32 | m, | ||
const double * | a, | ||
double * | b | ||
) | [inline] |
Compute . Compute , where is a matrix on and is (therefore) a matrix on , for .
n | Number of rows in a |
m | Number of columns in a and rows and columns in b |
a | Input matrix |
b | Output matrix |
Definition at line 743 of file linear_algebra.c.
int matrix_atawati | ( | u32 | n, |
u32 | m, | ||
const double * | a, | ||
const double * | w, | ||
double * | b | ||
) | [inline] |
Compute . Compute , where is a matrix on , is a diagonal weighting matrix on and is (therefore) a matrix on , for .
n | Number of rows in a and rows and columns in b |
m | Number of columns in a |
a | Input matrix |
w | Diagonal vector of weighting matrix |
b | Output matrix |
Definition at line 696 of file linear_algebra.c.
int matrix_atwaiat | ( | u32 | n, |
u32 | m, | ||
const double * | a, | ||
const double * | w, | ||
double * | b | ||
) | [inline] |
Compute . Compute , where is a matrix on , is a diagonal weighting matrix on and is (therefore) a matrix on , for .
n | Number of rows in a |
m | Number of columns in a and rows and columns in b |
a | Input matrix |
w | Diagonal vector of weighting matrix |
b | Output matrix |
Definition at line 647 of file linear_algebra.c.
void matrix_copy | ( | u32 | n, |
u32 | m, | ||
const double * | a, | ||
double * | b | ||
) |
Copy a matrix. Copy a matrix: , where and are matrices on .
n | Number of rows in and |
m | Number of columns in and |
a | Matrix to copy |
b | Copied (output) matrix |
Definition at line 840 of file linear_algebra.c.
int matrix_inverse | ( | u32 | n, |
const double const * | a, | ||
double * | b | ||
) | [inline] |
Invert a square matrix. Calculate the inverse of a square matrix: , where and are matrices on . For matrices size 4x4 and smaller, this is done by autogenerated hard-coded routines. For larger matrices, this is done by Gauss-Jordan elimination (which is ).
n | The rank of a and b |
a | The matrix to invert (input) |
b | Where to put the inverse (output) |
Definition at line 534 of file linear_algebra.c.
void matrix_multiply | ( | u32 | n, |
u32 | m, | ||
u32 | p, | ||
const double * | a, | ||
const double * | b, | ||
double * | c | ||
) | [inline] |
Multiply two matrices. Multiply two matrices: , where is a matrix on , is a matrix on and is (therefore) a matrix in .
n | Number of rows in a and c |
m | Number of columns in a and rows in b |
p | Number of columns in b and c |
a | First matrix to multiply |
b | Second matrix to multiply |
c | Output matrix |
Definition at line 782 of file linear_algebra.c.
int matrix_pseudoinverse | ( | u32 | n, |
u32 | m, | ||
const double * | a, | ||
double * | b | ||
) |
Invert a non-square matrix (least-squares or least-norm solution). If is of full rank, calculate the Moore-Penrose pseudoinverse of a square matrix:
If , then must be of full column rank, and solves the linear least-squares (overconstrained) problem:
If , then must be of full row rank, and solves the linear least-norm (underconstrained) problem:
If , then must be of full rank, and .
n | The number of rows in a |
m | The number of columns in a |
a | The matrix to invert (input) |
b | Where to put the inverse (output) |
Definition at line 622 of file linear_algebra.c.
void matrix_transpose | ( | u32 | n, |
u32 | m, | ||
const double * | a, | ||
double * | b | ||
) |
Transpose a matrix. Transpose a matrix: , where is a matrix on and is (therefore) a matrix on .
n | Number of rows in and columns in |
m | Number of rows in and columns in |
a | Matrix to transpose |
b | Transposed (output) matrix |
Definition at line 823 of file linear_algebra.c.
QR decomposition of a matrix. Compute the QR decomposition of an arbitrary matrix : where is an orthogonal matrix and is an upper-triangular matrix.
For an overdetermined (least-squares) problem, will be of the form
where is an upper-triangular matrix on .
A | The matrix to decompose (input) |
rows | How many rows in A |
cols | How many columns in A |
qt | (output) |
r | (output) |
Definition at line 103 of file linear_algebra.c.
s32 qrdecomp_square | ( | const double * | a, |
u32 | rows, | ||
double * | qt, | ||
double * | r | ||
) |
QR decomposition of a square matrix. Compute the QR decomposition of a square matrix : where is an orthogonal matrix and is an upper-triangular matrix.
Definition at line 257 of file linear_algebra.c.
Solve a linear system using the QR decomposition. Solve the linear system using the QR decomposition and backward substitution, where is a matrix on and and are vectors on .
a | Matrix (input) |
rows | Number of rows in a |
cols | Number of columns in a |
b | Vector (input) |
x | Vector (output) |
Definition at line 365 of file linear_algebra.c.
Solve Qx = b for x. Since is an orthogonal matrix, and therefore . This function computes in this way.
qt | to be used to solve for x (input) |
n | size of qt (it is square) |
b | to be used to solve for x (input) |
x | result of the linear solve (output) |
Definition at line 317 of file linear_algebra.c.
Definition at line 468 of file linear_algebra.c.
Definition at line 479 of file linear_algebra.c.
Solve Rx = b for x. Solve for . Since is upper-triangular, this can be done efficiently by back-substitution. This function has two important properties: it must never be called with an that results from the decomposition of a singular matrix, and it is safe to pass the same pointer for and .
r | Upper-triangular (input) |
rows | Number of rows in r |
cols | Number of columns in r |
b | Vector to solve against, from qtmult() |
x | Solution vector (output) |
Definition at line 341 of file linear_algebra.c.