Robotat Linalg
Loading...
Searching...
No Matches
Linsolve

Linear solver based on matf32_t data type of the Matf32 Library. The following methods are available for the solver: LU, QR, Cholesky, Forward Substitution, Backward Subtitution and SVD. More...

Enumerations

enum  linsolve_method_t {
  FORWARD_SUBS , BACKWARD_SUBS , CHOLESKY , QR_SQUARE ,
  QR_RECT , LU , SVD
}
 Enumerated list for the available methods of the linear solver. More...

Functions

void linsolve_print_method (linsolve_method_t lsm)
 Prints string representing the linear method.
linsolve_method_t linsolve_get_method (const matf32_t *const p_a)
 Defines which method is the best to use depending on the shape ant type of matrix in the system.
err_status_t linsolve_forward_substitution (const matf32_t *const p_l, const matf32_t *const p_b, matf32_t *p_x)
 Solves a linear system through forward substitution.
err_status_t linsolve_backward_substitution (const matf32_t *const p_u, const matf32_t *const p_b, matf32_t *p_x)
 Solves a system a linear system through backward substitution.
err_status_t linsolve_cholesky (matf32_t *const p_c, const matf32_t *const p_b, matf32_t *const p_x)
 Solves a linear system through Cholesky factorization. The factorization must be performed before executing this routine.
err_status_t linsolve_qr (matf32_t *const p_q, matf32_t *const p_r, const matf32_t *const p_b, matf32_t *const p_x, linsolve_method_t qr_shape)
 Solves a linear system through QR factorization. The factorization must be computed before using this routine. Can be applied to systems with either square or rectangular matrices, by introducing the QR_SQUARE or QR_RECT, respectively, in the linsolve_method_t argument. The system is solved as follows:
err_status_t linsolve_lu (const matf32_t *const p_l, const matf32_t *const p_u, const matf32_t *const p_b, matf32_t *const p_x, uint16_t *p_index)
 Solves a linear system through LU factorization. The factorization must be computed before executing this routine, as the factorization's matrices are introduced as arguments. The system is solved as follows:
err_status_t linsolve_svd (const matf32_t *const p_u, const matf32_t *const p_s, const matf32_t *const p_v, const matf32_t *const p_b, matf32_t *const p_x)
 Solves a linear system through SVD Factorization. The SVD must be computed before executing this routine as it receives the matrices of the decomposition as arguments. The solution to the system is computed as \( \textbf{x} = \textbf{V}\textbf{S}^{-1}\textbf{U}^\top\textbf{b} \).
err_status_t linsolve (const matf32_t *const p_a, const matf32_t *const p_b, matf32_t *const p_x)
 Solve a linear system of the form \( \textbf{Ax} = \textbf{b} \), automatically selecting the method to use based on the shape and type of input matrix.
err_status_t linsolve_method (const matf32_t *const p_a, const matf32_t *const p_b, matf32_t *p_x, linsolve_method_t method)
 Solve a linear system of the form \( \textbf{Ax} = \textbf{b} \) with a specific method selected in the arguments.

Detailed Description

Linear solver based on matf32_t data type of the Matf32 Library. The following methods are available for the solver: LU, QR, Cholesky, Forward Substitution, Backward Subtitution and SVD.

Date
Created on: 2022 By: Daniel Pineda
Last modified: 14 jan. 2026 By: Andrea Pineda

Enumeration Type Documentation

◆ linsolve_method_t

Enumerated list for the available methods of the linear solver.

Enumerator
FORWARD_SUBS 

Solve system with Forward Substitution

BACKWARD_SUBS 

Solve system with Backward Substitution

CHOLESKY 

Solve system with Cholesky Factorization

QR_SQUARE 

Solve system with QR Factorization for square matrices

QR_RECT 

Solve system with QR Factorization for rectangular matrices (vertical or horitzontal)

LU 

Solve system with LU Factorization

SVD 

Solve system with the Singular Value Decomposition (SVD)

Function Documentation

◆ linsolve()

err_status_t linsolve ( const matf32_t *const p_a,
const matf32_t *const p_b,
matf32_t *const p_x )

Solve a linear system of the form \( \textbf{Ax} = \textbf{b} \), automatically selecting the method to use based on the shape and type of input matrix.

Warning
This solver does uses QR only for systems with rectangular matrices. To solve square matrix systems with QR, use linsolve_method instead. Additionally, the ill-conditioned theshold can be modified in constants.h, according to your needs.
Parameters
[in]p_aPoints to system matrix.
[in]p_bPoints to b vector.
[in,out]p_xPoints to output x vector.
Returns
Returns execution status err_status_t: MATH_SUCCESS : Operation successful, MATH_SIZE_MISMATCH : Matrix size check failed, MATH_DECOMPOSITION_FAILURE : Failed decomposition method, MATH_ARGUMENT_ERROR : Incorrect arguments passed.
Here is the call graph for this function:

◆ linsolve_backward_substitution()

err_status_t linsolve_backward_substitution ( const matf32_t *const p_u,
const matf32_t *const p_b,
matf32_t * p_x )

Solves a system a linear system through backward substitution.

Warning
Only applicable to systems where the matrix is upper triangular.
Parameters
[in]p_uPoints to lower triangular matrix.
[in]p_bPoints to b vector.
[in,out]p_xPoints to output x vector.
Returns
Returns execution status err_status_t: MATH_SUCCESS : Operation successful, MATH_ARGUMENT_ERROR : Upper triangular matrix check failed.
Here is the call graph for this function:

◆ linsolve_cholesky()

err_status_t linsolve_cholesky ( matf32_t *const p_c,
const matf32_t *const p_b,
matf32_t *const p_x )

Solves a linear system through Cholesky factorization. The factorization must be performed before executing this routine.

  1. Solve \( \textbf{L}\textbf{y} = \textbf{b} \)
  2. Solve \( \textbf{L$^\top$}\textbf{x} = \textbf{y} \)
Warning
This method assumes that the Cholesky factor matrix is introduced as an upper triangular matrix, exactly as the matf32_cholesky algorithm generates it. The solution to the system will be incorrect if the Cholesky Factor is introduced as a lower triangular matrix into the function.
Parameters
[in]p_cPoints to upper triangular matrix.
[in]p_bPoints to b vector.
[in,out]p_xPoints to output vector x.
Returns
Returns execution status err_status_t: MATH_SUCCESS : Operation successful, MATH_ARGUMENT_ERROR : Input matrix checks in forward or backward substitution failed.
Here is the call graph for this function:

◆ linsolve_forward_substitution()

err_status_t linsolve_forward_substitution ( const matf32_t *const p_l,
const matf32_t *const p_b,
matf32_t * p_x )

Solves a linear system through forward substitution.

Warning
Only applicable to systems where the matrix is lower triangular.
Parameters
[in]p_lPoints to lower triangular matrix.
[in]p_bPoints to b vector.
[in,out]p_xPoints to output x vector.
Returns
Returns execution status err_status_t: MATH_SUCCESS : Operation successful, MATH_ARGUMENT_ERROR : Lower triangular matrix check failed.
Here is the call graph for this function:

◆ linsolve_get_method()

linsolve_method_t linsolve_get_method ( const matf32_t *const p_a)

Defines which method is the best to use depending on the shape ant type of matrix in the system.

Parameters
[in]p_aPoints to system matrix.
Returns
Returns a value of type linsolve_method_t: FORWARD_SUBS : Forward substitution, BACKWARD_SUBS : Backward substitution, CHOLESKY : Cholesky factorization, QR_SQUARE : QR factorization for square matrices, QR_RECT : QR factorization for rectangular matrices, LU : LU factorization, SVD : Singular Values Decomposition.
Here is the call graph for this function:

◆ linsolve_lu()

err_status_t linsolve_lu ( const matf32_t *const p_l,
const matf32_t *const p_u,
const matf32_t *const p_b,
matf32_t *const p_x,
uint16_t * p_index )

Solves a linear system through LU factorization. The factorization must be computed before executing this routine, as the factorization's matrices are introduced as arguments. The system is solved as follows:

  1. Solve the system \( \textbf{Ly} = \textbf{b} \)
  2. Then solve the system \( \textbf{Ux} = \textbf{y} \)
Parameters
[in]p_lPoints to matrix L from LU decomposition of A.
[in]p_uPoints to matrix U from LU decomposition of A.
[in]p_bPoints to b vector.
[in,out]p_xPoints to output vector x.
[in]p_indexList of permutations executed during the LU decomposition of A.
Returns
Returns execution status err_status_t: MATH_SUCESS : Operation successful, MATH_ARGUMENT_ERROR : Input matrix checks in forward or backward substitution failed.
Here is the call graph for this function:

◆ linsolve_method()

err_status_t linsolve_method ( const matf32_t *const p_a,
const matf32_t *const p_b,
matf32_t * p_x,
linsolve_method_t method )

Solve a linear system of the form \( \textbf{Ax} = \textbf{b} \) with a specific method selected in the arguments.

Parameters
[in]p_aPoints to system matrix.
[in]p_bPoints to b vector.
[in,out]p_xPoints to output x vector.
[in]methodMethod to use.
Returns
Returns execution status err_status_t: MATH_SUCCESS : Operation successful, MATH_SIZE_MISMATCH : Matrix size check failed, MATH_DECOMPOSITION_FAILURE : Failed decomposition method, MATH_ARGUMENT_ERROR : Incorrect arguments passed.
Here is the call graph for this function:

◆ linsolve_print_method()

void linsolve_print_method ( linsolve_method_t lsm)

Prints string representing the linear method.

Parameters
[in]lsmMethod to use
Returns
None.

◆ linsolve_qr()

err_status_t linsolve_qr ( matf32_t *const p_q,
matf32_t *const p_r,
const matf32_t *const p_b,
matf32_t *const p_x,
linsolve_method_t qr_shape )

Solves a linear system through QR factorization. The factorization must be computed before using this routine. Can be applied to systems with either square or rectangular matrices, by introducing the QR_SQUARE or QR_RECT, respectively, in the linsolve_method_t argument. The system is solved as follows:

  1. Compute the vector \( \textbf{y} = \textbf{Q}^\top \textbf{b} \)
  2. Solve the system \( \textbf{Rx} = \textbf{y} \)
Parameters
[in]p_qPoints to matrix q from QR decomposition of A.
[in]p_rPoints to matrix R from QR decomposition of A.
[in]p_bPoints to b vector.
[in,out]p_xPoints to output vector x.
Returns
Returns execution status err_status_t: MATH_SUCCESS : Operation successful, MATH_ARGUMENT_ERROR : Input matrix check in backward substitution failed.
Here is the call graph for this function:

◆ linsolve_svd()

err_status_t linsolve_svd ( const matf32_t *const p_u,
const matf32_t *const p_s,
const matf32_t *const p_v,
const matf32_t *const p_b,
matf32_t *const p_x )

Solves a linear system through SVD Factorization. The SVD must be computed before executing this routine as it receives the matrices of the decomposition as arguments. The solution to the system is computed as \( \textbf{x} = \textbf{V}\textbf{S}^{-1}\textbf{U}^\top\textbf{b} \).

Parameters
[in]p_uPoints to matrix U from SVD of A
[in]p_sPoints to matrix S from SVD of A
[in]p_vPoints to matrix V from SVD of A
[in]p_bPoints to b vector
[in,out]p_xPoints to output vector x
Returns
Returns execution status err_status_t: MATH_SUCCESS : Operation successful
Here is the call graph for this function: