rsLQR  0.1
linalg_custom.h File Reference

Simple linear algebra routines. More...

#include "matrix.h"

Go to the source code of this file.

int clap_MatrixAddition (Matrix *A, Matrix *B, double alpha)
 Add two matrices of the same size, storing the result in B. More...
 
int clap_MatrixScale (Matrix *A, double alpha)
 Scale a matrix by a constant. More...
 
int clap_MatrixMultiply (Matrix *A, Matrix *B, Matrix *C, bool tA, bool tB, double alpha, double beta)
 Matrix multiplication. More...
 
int clap_MatrixTransposeMultiply (Matrix *A, Matrix *B, Matrix *C)
 A shortcut to perform transposed matrix multiplication. More...
 
int clap_SymmetricMatrixMultiply (Matrix *Asym, Matrix *B, Matrix *C, double alpha, double beta)
 Matrix multiplication with a symmetric matrix A. More...
 
int clap_AddDiagonal (Matrix *A, double alpha)
 Add a constant value to the diagonal of a matrix. More...
 
int clap_CholeskyFactorize (Matrix *A)
 Perform a Cholesky decomposition. More...
 
int clap_CholeskySolve (Matrix *A, Matrix *b)
 Solve a linear system of equation with a precomputed Cholesky decomposition. More...
 
int clap_LowerTriBackSub (Matrix *L, Matrix *b, bool istransposed)
 Solve a linear system of equation for a lower triangular matrix. More...
 

Detailed Description

Simple linear algebra routines.

Author
Brian Jackson (bjack.nosp@m.205@.nosp@m.gmail.nosp@m..com)
Version
0.1
Date
2022-01-31

Function Documentation

◆ clap_AddDiagonal()

int clap_AddDiagonal ( Matrix A,
double  alpha 
)

Add a constant value to the diagonal of a matrix.

Parameters
[in,out]Aa matrix of size (n,m) where n <= m
[in]alphascalar to add to the diagonal
Returns
0 if successful

◆ clap_CholeskyFactorize()

int clap_CholeskyFactorize ( Matrix A)

Perform a Cholesky decomposition.

Performs a Cholesky decomposition on the square matrix A, storing the result in the lower triangular portion of A.

Parameters
Aa square symmetric matrix
Returns
clap_kCholeskySuccess if successful, and clap_kCholeskyFail if not.

◆ clap_CholeskySolve()

int clap_CholeskySolve ( Matrix A,
Matrix b 
)

Solve a linear system of equation with a precomputed Cholesky decomposition.

Parameters
[in]AA square matrix whose Cholesky decomposition is stored in the lower triangular portion of the matrix
[in,out]bThe right-hand-side vector. Stores the solution upon completion of the function.
Returns
0 if successful

◆ clap_LowerTriBackSub()

int clap_LowerTriBackSub ( Matrix L,
Matrix b,
bool  istransposed 
)

Solve a linear system of equation for a lower triangular matrix.

Uses backsubstitution to solve a system of equations of the following form:

\[ L x = b \]

for a lower-triangular matrix \( L \), or

\[ L^T x = b \]

if istransposed is true.

Parameters
[in]LA lower-triangular matrix
[in,out]bThe right-hand-side vector. Stores the solution upon completion.
istransposedShould L be transposed when solving the system of equations.
Returns
0 if successful

◆ clap_MatrixAddition()

int clap_MatrixAddition ( Matrix A,
Matrix B,
double  alpha 
)

Add two matrices of the same size, storing the result in B.

Performs the following operation:

\[ B = B + \alpha A \]

Parameters
[in]Aany matrix of size (m,n)
[in,out]Bany matrix of size (m,n)
[in]alphascalar factor on A
Returns
0 if successful

◆ clap_MatrixMultiply()

int clap_MatrixMultiply ( Matrix A,
Matrix B,
Matrix C,
bool  tA,
bool  tB,
double  alpha,
double  beta 
)

Matrix multiplication.

\[ C = \alpha A B + \beta C \]

Parameters
[in]AMatrix of size (m,n)
[in]BMatrix of size (n,p)
[in,out]COutput matrix of size (m,p)
[in]tAShould A be transposed
[in]tBShould B be transposed
[in]alphascalar on the \( A B \) term
[in]betascalar on the \( C \) term. Set to zero for pure matrix multiplication.

◆ clap_MatrixScale()

int clap_MatrixScale ( Matrix A,
double  alpha 
)

Scale a matrix by a constant.

Parameters
Aany matrix of non-zero size
alphascalar multiplier
Returns
0 if successful

◆ clap_MatrixTransposeMultiply()

int clap_MatrixTransposeMultiply ( Matrix A,
Matrix B,
Matrix C 
)

A shortcut to perform transposed matrix multiplication.

Calculates

\[ C = A^T B \]

Parameters
[in]Aany matrix of size (n,m)
[in]Bany matrix of size (n,p)
[out]Cany matrix of size (m,p)
Returns

◆ clap_SymmetricMatrixMultiply()

int clap_SymmetricMatrixMultiply ( Matrix Asym,
Matrix B,
Matrix C,
double  alpha,
double  beta 
)

Matrix multiplication with a symmetric matrix A.

Perform the following computation

\[ C = \alpha A B + \beta C \]

For a symmetric matrix \( A \).

Parameters
[in]Asym
[in]B
[in,out]C
[in]alpha
[in]beta