Robot Control Library
algebra.h
Go to the documentation of this file.
1 /**
2  * <rc/math/algebra.h>
3  *
4  * @brief advanced linear algebra functions
5  *
6  * @addtogroup Algebra
7  * @ingroup Math
8  * @{
9  */
10 
11 #ifndef RC_ALGEBRA_H
12 #define RC_ALGEBRA_H
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #include <rc/math/matrix.h>
19 
20 /**
21  * @brief Performs LUP decomposition on matrix A with partial pivoting.
22  *
23  * Places the result in matrices L,U,&P. Matrix A remains untouched and the
24  * original contents of LUP (if any) are freed and LUP are resized
25  * appropriately.
26  *
27  * @param[in] A input matrix
28  * @param[out] L lower triangular
29  * @param[out] U upper triangular
30  * @param[out] P permutation matrix
31  *
32  * @return Returns 0 on success or -1 on failure.
33  */
35 
36 /**
37  * @brief Calculate the QR decomposition of matrix A.
38  *
39  * Uses householder reflection method. Matrix A remains untouched and the
40  * original contents of Q&R (if any) are freed and resized appropriately.
41  *
42  * @param[in] A input matrix
43  * @param[out] Q orthogonal matrix output
44  * @param[out] R upper triangular matrix output
45  *
46  * @return Returns 0 on success or -1 on failure.
47  */
49 
50 /**
51  * @brief Inverts matrix A via LUP decomposition method.
52  *
53  * Places the result in matrix Ainv. Any existing memory allocated for Ainv is
54  * freed if necessary and its contents are overwritten. Returns -1 if matrix is
55  * not invertible.
56  *
57  * @param[in] A input matrix
58  * @param[out] Ainv resulting inverted matrix
59  *
60  * @return Returns 0 on success or -1 on failure.
61  */
63 
64 /**
65  * @brief Inverts matrix A in place.
66  *
67  * The original contents of A are lost. Returns -1 if A is not invertible.
68  *
69  * @param A matrix to be inverted
70  *
71  * @return Returns 0 on success or -1 on failure.
72  */
74 
75 /**
76  * @brief Solves Ax=b for given matrix A and vector b.
77  *
78  * Places the result in vector x. existing contents of x are freed and new
79  * memory is allocated if necessary.
80  *
81  * @param[in] A matrix A
82  * @param[in] b column vector b
83  * @param[out] x solution column vector
84  *
85  * @return Returns 0 on success or -1 on failure.
86  */
88 
89 /**
90  * @brief Sets the zero tolerance for detecting singular matrices.
91  *
92  * When inverting matrices or solving a linear system, this library first checks
93  * that the determinant of the matrix is non-zero. Due to the rounding errors
94  * that come from float-point math, we cannot check if the determinant is
95  * exactly zero. Instead, it is checked to be smaller in magnitude than the
96  * zero-tolerance.
97  *
98  * The default value is 10^-8 but it can be changed here if the user is dealing
99  * with unusually small or large floating point values.
100  *
101  * This only effects the operation of rc_algebra_invert_matrix,
102  * rc_algebra_invert_matrix_inplace, and rc_algebra_lin_system_solve.
103  *
104  * @param[in] tol The zero-tolerance
105  */
106 void rc_algebra_set_zero_tolerance(double tol);
107 
108 /**
109  * @brief Finds a least-squares solution to the system Ax=b for non-square
110  * A using QR decomposition method.
111  *
112  * Places the solution in x.
113  *
114  * @param[in] A matrix A
115  * @param[in] b column vector b
116  * @param[out] x solution column vector
117  *
118  * @return Returns 0 on success or -1 on failure.
119  */
121 
122 /**
123  * @brief Fits an ellipsoid to a set of points in 3D space.
124  *
125  * The principle axes of the fitted ellipsoid align with the global coordinate
126  * system. Therefore there are 6 degrees of freedom defining the ellipsoid: the
127  * x,y,z coordinates of the centroid and the lengths from the centroid to the
128  * surface in each of the 3 directions.
129  *
130  * rc_matrix_t 'points' is a tall matrix with 3 columns and at least 6 rows.
131  * Each row must contain the x,y&z components of each individual point to be
132  * fit. If only 6 rows are provided, the resulting ellipsoid will be an exact
133  * fit. Otherwise the result is a least-squares fit to the over-defined dataset.
134  *
135  * The final x,y,z position of the centroid will be placed in vector 'center'
136  * and the lengths or radius from the centroid to the surface along each axis
137  * will be placed in the vector 'lengths'
138  *
139  * @param[in] points datapoints to fit
140  * @param[out] center center of ellipse
141  * @param[out] lengths lengths along principle axis
142  *
143  * @return Returns 0 on success or -1 on failure.
144  */
145 int rc_algebra_fit_ellipsoid(rc_matrix_t points, rc_vector_t* center, rc_vector_t* lengths);
146 
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
152 #endif // RC_ALGEBRA_H
153 
154 /** @} end group math*/
int rc_algebra_qr_decomp(rc_matrix_t A, rc_matrix_t *Q, rc_matrix_t *R)
Calculate the QR decomposition of matrix A.
int rc_algebra_fit_ellipsoid(rc_matrix_t points, rc_vector_t *center, rc_vector_t *lengths)
Fits an ellipsoid to a set of points in 3D space.
Struct containing the state of a vector and a pointer to dynamically allocated memory to hold its con...
Definition: vector.h:41
int rc_algebra_lup_decomp(rc_matrix_t A, rc_matrix_t *L, rc_matrix_t *U, rc_matrix_t *P)
Performs LUP decomposition on matrix A with partial pivoting.
void rc_algebra_set_zero_tolerance(double tol)
Sets the zero tolerance for detecting singular matrices.
int rc_algebra_invert_matrix(rc_matrix_t A, rc_matrix_t *Ainv)
Inverts matrix A via LUP decomposition method.
int rc_algebra_lin_system_solve_qr(rc_matrix_t A, rc_vector_t b, rc_vector_t *x)
Finds a least-squares solution to the system Ax=b for non-square A using QR decomposition method...
int rc_algebra_invert_matrix_inplace(rc_matrix_t *A)
Inverts matrix A in place.
Struct containing the state of a matrix and a pointer to dynamically allocated memory to hold its con...
Definition: matrix.h:32
int rc_algebra_lin_system_solve(rc_matrix_t A, rc_vector_t b, rc_vector_t *x)
Solves Ax=b for given matrix A and vector b.