Header of the lineal algebra routines used in the CuikSuite.
This file includes high level routines which require LU or QR decompositions, and similar procedures.
 See Also
 algebra.c
Definition in file algebra.h.

int  MatrixDeterminantSgn (double epsilon, unsigned int n, double *A) 
 Sign of the determinant of a matrix. More...


double  MatrixDeterminant (unsigned int n, double *A) 
 Determinant of a matrix. More...


unsigned int  FindRank (double epsilon, unsigned int nr, unsigned int nc, double *mT) 
 Determines the rowrank of a matrix. More...


unsigned int  FindKernel (unsigned int nr, unsigned int nc, double *mT, unsigned int dof, boolean check, double epsilon, double **T) 
 Computes the kernel of a matrix. More...


unsigned int  FindKernelAndIndependentRows (unsigned int nr, unsigned int nc, double *mT, unsigned int dof, double epsilon, boolean *singular, boolean **IR, double **T) 
 Computes the kernel of a matrix and determines the independent rows of this matrix. More...


void  InitNewton (unsigned int nr, unsigned int nc, TNewton *n) 
 Defines a Newton structure. More...


double *  GetNewtonMatrixBuffer (TNewton *n) 
 Buffer to store the Newton matrix. More...


double *  GetNewtonRHBuffer (TNewton *n) 
 Buffer to store the Newton right hand. More...


void  NewtonSetMatrix (unsigned int i, unsigned int j, double v, TNewton *n) 
 Defines the matrix being used in a Newton step. More...


void  NewtonSetRH (unsigned int i, double v, TNewton *n) 
 Defines the vector being used in a Newton step. More...


int  NewtonStep (double nullSingularValue, double *x, double *dif, TNewton *n) 
 One step in a Newton iteration. More...


double  NewtonGetResult (unsigned int i, TNewton *n) 
 Gets the vector resulting from a Newton step. More...


void  DeleteNewton (TNewton *n) 
 Releases a Newton structure. More...


void  InitLS (unsigned int nr, unsigned int nc, TLinearSystem *ls) 
 Defines a linear system structure. More...


double *  GetLSMatrixBuffer (TLinearSystem *ls) 
 Buffer to store the A matrix. More...


double *  GetLSRHBuffer (TLinearSystem *ls) 
 Buffer to store the linear system right hand (RH). More...


double *  GetLSSolutionBuffer (TLinearSystem *ls) 
 Buffer to store the linear system solution. More...


void  LSSetMatrix (unsigned int i, unsigned int j, double v, TLinearSystem *ls) 
 Defines the matrix being used in a linear system. More...


void  LSSetRH (unsigned int i, double v, TLinearSystem *ls) 
 Defines the vector being used in a linear system. More...


int  LSSolve (TLinearSystem *ls) 
 Solves the linear sytem. More...


void  DeleteLS (TLinearSystem *ls) 
 Releases a linear system structure. More...


int MatrixDeterminantSgn 
( 
double 
epsilon, 


unsigned int 
n, 


double * 
A 

) 
 
Sign of the determinant of a squared matrix.
 Parameters

epsilon  Numerical accuracy. 
n  Number of rows/columsn of the matrix. 
A  The matrix. 
 Returns
 The matrix determinant sign (1,0,1).
Referenced by GetChartDegree().
double MatrixDeterminant 
( 
unsigned int 
n, 


double * 
A 

) 
 
Determinant of a squared matrix.
This function must be used with caution (only for small matrices) since the determinant can easily overflow.
 Parameters

n  Number of rows/columsn of the matrix. 
A  The matrix. 
 Returns
 The matrix determinant.
Referenced by CompareTangentSpaces().
unsigned int FindRank 
( 
double 
epsilon, 


unsigned int 
nr, 


unsigned int 
nc, 


double * 
mT 

) 
 
Determines the rank of a matrix, i.e. the dimension of the space spanned by the rows/column of the matrix.
For a given problem, the number of variables minus the rank of the Jacobian gives the dimensionality of the solution space, assuming that the Jacobian is evaluated in a regular point. The dimensionality of the solution space is the same as that of its tangent space.
 Parameters

epsilon  Numerical accuracy. 
nr  Number of rows of the matrix (no transposed). 
nc  Number of colimns of teh matrix (no transposed). 
mT  The TRANSPOSED matrix. 
 Returns
 The rank of the matrix. NO_UINT if the rank can not be computed.
Definition at line 1084 of file algebra.c.
References AnalyzeKernel(), FALSE, and TRUE.
Referenced by InitAtlasFromPoint().
unsigned int FindKernel 
( 
unsigned int 
nr, 


unsigned int 
nc, 


double * 
mT, 


unsigned int 
dof, 


boolean 
check, 


double 
epsilon, 


double ** 
T 

) 
 
Defines a basis of the null space of a matrix.
 Parameters

nr  Number of rows of the matrix (no transposed). 
nc  Numbe of columns of the matrix (no transposed). 
mT  The TRANSPOSED matrix stored as a vector. 
dof  Expected dimension of the kernel. 
check  If TRUE the function introduces some consistancy checks (whether the kernel dimensionality is larger or smaller than the expected one). 
epsilon  Values below epsilon are taken as zero. 
T  The output kernel. This is a (nc x dof) matrix (stored as a vector). The space for this matrix is allocated in this function but must be deallocated externally. 
 Returns
 0 if all the operations are correct, 1 if there the kernel is too large (i.e., the given point is singular), 2 if the chart could not be defined since the kernel is too small at the given point, and 3 if there is an error while performing QR decomposition. These outputs come directly from AnalyzeKernel.
Definition at line 1098 of file algebra.c.
References AnalyzeKernel(), FALSE, and TRUE.
Referenced by FindRightNullVector(), and RefineSingularPoint().
unsigned int FindKernelAndIndependentRows 
( 
unsigned int 
nr, 


unsigned int 
nc, 


double * 
mT, 


unsigned int 
dof, 


double 
epsilon, 


boolean * 
singular, 


boolean ** 
IR, 


double ** 
T 

) 
 
Defines a basis of the null space of a matrix and determines a subset of the rows of the matrix that are independent.
This is useful because in our case most (all?) the matrices have redundancy (i.e., rows that are linearly dependent on other rows). However, for some purposes we need to determine a subset of the rows that are linearly independent.
 Parameters

nr  Number of rows of the matrix (no transposed). 
nc  Numbe of columns of the matrix (no transposed). 
mT  The TRANSPOSED matrix stored as a vector. 
dof  Expected dimension of the kernel. If zero, the function tries to determine the rank automatically. 
epsilon  Values below epsilon are taken as zero. 
singular  TRUE if the matrix is singular (has more null eigen values than the expected ones). Output. 
IR  The set of independent rows as a boolean vector with as many entriees as rows in the input matrix and TRUE for the independent rows. The space for this vector is allocated here but must be deallocated externally. If the matrix is singular this contains the most likely basis of the matrix (up to the numerical accuracy). Caution must be taken to use this output in this case. 
T  The output kernel. This is a (nc x dof) matrix (stored as a vector). The space for this matrix is allocated in this function but must be deallocated externally. 
 Returns
 0 if all the operations are correct, 1 if there the kernel is too large (i.e., the given point is singular), 2 if the chart could not be defined since the kernel is too small at the given point, and 3 if there is an error while performing QR decomposition. These outputs come directly from AnalyzeKernel.
Definition at line 1112 of file algebra.c.
References AnalyzeKernel(), FALSE, and TRUE.
Referenced by ComputeJacobianKernelBasis().
void InitNewton 
( 
unsigned int 
nr, 


unsigned int 
nc, 


TNewton * 
n 

) 
 
Initializes the structure to be used in a iterative Newton process.
Note that the dimensionality of the solution set can be deduced at each Newton step (using the QR with pivoting) but it is more efficient if we know it beforehand.
 Parameters

nr  Number of rows. 
nc  Number of columns. 
n  The Newton structure to initialize. 
Referenced by CuikNewtonInBox(), CuikNewtonSimp(), Newton2ManifoldPlane(), and RefineSingularPoint().
double* GetNewtonMatrixBuffer 
( 
TNewton * 
n  ) 


inline 
double* GetNewtonRHBuffer 
( 
TNewton * 
n  ) 


inline 
void NewtonSetMatrix 
( 
unsigned int 
i, 


unsigned int 
j, 


double 
v, 


TNewton * 
n 

) 
 

inline 
Sets one element of the matrix to be used in one Newton step. This matrix is typically initilized externally, but here we provide a mehtod to set it.
 Parameters

i  The row. 
j  The column. 
v  The new value. 
n  The Newton structure to set. 
Definition at line 1136 of file algebra.c.
References RC2INDEX.
Referenced by CuikNewtonInBox().
void NewtonSetRH 
( 
unsigned int 
i, 


double 
v, 


TNewton * 
n 

) 
 

inline 
Sets one element of the vector to be used in one Newton step. This vector is typically initilized externally, but here we provide a mehtod to set it.
 Parameters

i  The index in the vector. 
v  The new value. 
n  The Newton structure to set. 
Definition at line 1141 of file algebra.c.
Referenced by CuikNewtonInBox().
int NewtonStep 
( 
double 
nullSingularValue, 


double * 
x, 


double * 
dif, 


TNewton * 
n 

) 
 
Computes and applies the correction in one step of a Newton iteration.
This function allows to easily apply Newton processes just defining the input data (A, b), setting the initial value for x, and allocating space for the process. The space for the process is not allocated inside this function to avoid continous malloc/free calls since this function is typically used many times in a row.
Note that when executing this function the Newton matrix is modified. It is reused to store part of its SVD).
 Parameters

nullSingularValue  Singular values below this are set to zero. 
x  The current approximation to the system solution. This is updated internally. 
dif  Norm of the change applied to x. 
n  The Newton information. 
 Returns
 0 if no error is encountered in the Newton step.
Referenced by CuikNewtonInBox(), CuikNewtonSimp(), Newton2ManifoldPlane(), and RefineSingularPoint().
double NewtonGetResult 
( 
unsigned int 
i, 


TNewton * 
n 

) 
 
Gets one element of the vector resulting from a Newton step.
 Parameters

i  The index in the vector. 
n  The Newton structure to set. 
 Returns
 The value of the vector at the given index.
void DeleteNewton 
( 
TNewton * 
n  ) 

void InitLS 
( 
unsigned int 
nr, 


unsigned int 
nc, 


TLinearSystem * 
ls 

) 
 
Initializes the structure to be used when solving a linear system.
 Parameters

nr  Number of rows. 
nc  Number of columns. 
ls  The Newton structure to initialize. 
Referenced by Chart2Manifold().
double* GetLSMatrixBuffer 
( 
TLinearSystem * 
ls  ) 


inline 
Buffer to store the A matrix.
This buffer must be accessed using the RC2INDEX macro since the matrix can be stored row major or column major depending on the underlying lineal algebra library being used.
 Parameters

ls  The linear system structure. 
 Returns
 A pointer to the buffer where to store the matrix.
Definition at line 1146 of file algebra.c.
Referenced by Chart2Manifold().
double* GetLSRHBuffer 
( 
TLinearSystem * 
ls  ) 


inline 
Buffer to store the linear sytem RH.
 Parameters

ls  The linear system structure. 
 Returns
 A pointer to the buffer where to store the RH.
Definition at line 1151 of file algebra.c.
Referenced by Chart2Manifold().
double* GetLSSolutionBuffer 
( 
TLinearSystem * 
ls  ) 


inline 
Buffer to store the linear sytem solution.
 Parameters

ls  The linear system structure. 
 Returns
 A pointer to the buffer where to store the RH.
Definition at line 1156 of file algebra.c.
Referenced by Chart2Manifold().
void LSSetMatrix 
( 
unsigned int 
i, 


unsigned int 
j, 


double 
v, 


TLinearSystem * 
ls 

) 
 

inline 
Sets one element of the matrix to be used in a linear system.
 Parameters

i  The row. 
j  The column. 
v  The new value. 
ls  The linear system structure. 
Definition at line 1161 of file algebra.c.
References RC2INDEX.
void LSSetRH 
( 
unsigned int 
i, 


double 
v, 


TLinearSystem * 
ls 

) 
 

inline 
Sets one element of the right hand vector of a linear system.
 Parameters

i  The index in the vector. 
v  The new value. 
ls  The linear system structure. 
Definition at line 1166 of file algebra.c.
int LSSolve 
( 
TLinearSystem * 
ls  ) 

Computes the solution of a linear system.
Note that when using solve, matrix A gets affected (it is reused to store its QR decomposition).
 Returns
 0 if no error is encountered when solving the system.
Referenced by Chart2Manifold().
void DeleteLS 
( 
TLinearSystem * 
ls  ) 

Releases the memory allocated for a linear system.
 Parameters

ls  A linear system structure. 
Referenced by Chart2Manifold().

Follow us!