RcdMathLib_doc
Open Source Library for Linear and Non-linear Algebra
matrix.h File Reference

Matrix computations. More...

#include <inttypes.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  matrix_dim_t
 A structure to define the row and column number of a matrix. More...
 

Macros

#define matrix_t   double
 Define the data type of the matrix elements. More...
 
#define MACHEPS   2E-16
 
#define M_PI   3.14159265358979323846
 

Functions

void matrix_init (uint8_t m, uint8_t n, matrix_t matrix[m][n], matrix_t value)
 Initialize all the elements of the matrix with a specified value. More...
 
void matrix_clear (uint8_t m, uint8_t n, matrix_t matrix[m][n])
 Clear all the elements of the vector. More...
 
void matrix_transpose (uint8_t m, uint8_t n, matrix_t src_matrix[m][n], matrix_t dest_matrix[n][m])
 Computes the transpose of a matrix. More...
 
void matrix_in_place_transpose (uint8_t m, matrix_t matrix[][m])
 Computes the in-place transpose of a matrix. More...
 
void matrix_copy (uint8_t m, uint8_t n, matrix_t src_matrix[m][n], matrix_t dest_matrix[m][n])
 Copy the elements of a matrix to another matrix. More...
 
void matrix_part_copy (uint8_t m, uint8_t n, matrix_t src_matrix[m][n], uint8_t start_row_ind, uint8_t end_row_ind, uint8_t start_col_ind, uint8_t end_col_ind, uint8_t dest_row_num, uint8_t dest_col_num, matrix_t dest_matrix[][dest_col_num])
 Copy a part of a matrix to another matrix or sub-matrix. More...
 
uint8_t matrix_get_rank (uint8_t m, uint8_t n, matrix_t singl_values_arr[], uint8_t length)
 Compute the rank of a matrix. More...
 
void matrix_add (uint8_t m, uint8_t n, matrix_t A[m][n], matrix_t B[m][n], matrix_t A_plus_B[m][n])
 Compute the addition of two matrices. More...
 
void matrix_add_to_diag (uint8_t n, matrix_t A[][n], uint8_t diag_el_num, matrix_t value)
 Add a number to diagonal elements of a matrix. More...
 
void matrix_sub (uint8_t m, uint8_t n, matrix_t A[m][n], matrix_t B[m][n], matrix_t A_minus_B[m][n])
 Compute the subtraction of two matrices. More...
 
void matrix_mul (uint8_t a_line_num, uint8_t a_col_num, matrix_t a_matrix[a_line_num][a_col_num], uint8_t b_line_num, uint8_t b_col_num, matrix_t b_matrix[b_line_num][b_col_num], matrix_t dest_matrix[a_line_num][b_col_num])
 Compute the multiplication of two matrices. More...
 
void matrix_part_mul (uint8_t a_col_num_max, matrix_t a_matrix[][a_col_num_max], uint8_t b_col_num_max, matrix_t b_matrix[][b_col_num_max], uint8_t a_start_row_ind, uint8_t a_end_row_ind, uint8_t a_start_col_ind, uint8_t a_end_col_ind, uint8_t b_start_row_ind, uint8_t b_end_row_ind, uint8_t b_start_col_ind, uint8_t b_end_col_ind, uint8_t dest_col_size, matrix_t dest_matrix[][dest_col_size])
 Compute the partial multiplication of two matrices. More...
 
void matrix_mul_vec (uint8_t m, uint8_t n, matrix_t matrix[m][n], matrix_t vec[n], matrix_t dst_arr[m])
 Compute the multiplication of a matrix with a column vector. More...
 
void matrix_trans_mul_vec (uint8_t m, uint8_t n, matrix_t A[m][n], uint8_t b_size, matrix_t b_vec[m], matrix_t c_vec[n])
 Compute the multiplication of transposed matrix with column vector. More...
 
void matrix_mul_col_vec_row_vec (uint8_t m, matrix_t col_vec[m], uint8_t n, matrix_t row_vec[n], uint8_t max_n, matrix_t res_mat[][max_n])
 Compute the multiplication of a column and row vector. More...
 
void matrix_vec_mul_matr (uint8_t m, uint8_t n, matrix_t vec[m], matrix_t matrix[m][n], matrix_t dst_arr[n])
 Compute the multiplication of row vector and a matrix. More...
 
void matrix_mul_scalar_vec_matr (uint8_t m, uint8_t n, matrix_t scalar, matrix_t vec[m], matrix_t matrix[m][n], matrix_t dst_arr[n])
 Compute the multiplication of a scalar with row vector and a matrix. More...
 
void matrix_trans_mul_itself (uint8_t m, uint8_t n, matrix_t A[m][n], matrix_t AT_mul_A[n][n])
 Compute the multiplication of the transpose of a matrix with itself. More...
 
void matrix_set_diag_elements (uint8_t m, uint8_t n, matrix_t value, matrix_t diag_matrix[m][n])
 Set all the diagonal elements of a matrix with a specified value. More...
 
void matrix_get_diag_mat_new (uint8_t m, uint8_t n, matrix_t diag_matrix[m][n], uint8_t length, matrix_t vec[])
 Set all the diagonal elements of a matrix with values that are saved in a vector. More...
 
void matrix_get_diag_mat (uint8_t m, uint8_t n, matrix_t value, matrix_t diag_matrix[m][n])
 Create a diagonal matrix with a specified value. More...
 
void matrix_mul_scalar (uint8_t m, uint8_t n, matrix_t mat_src[m][n], matrix_t value, matrix_t mat_dest[m][n])
 Multiply all elements of a matrix with a specified value. More...
 
void matrix_get_column_vec (uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t col_num, matrix_t col_vec[m])
 Get a column of a matrix. More...
 
void matrix_get_part_column_vec (uint8_t max_m, uint8_t max_n, matrix_t matrix[max_m][max_n], uint8_t col_num, uint8_t offset, matrix_t col_vec[max_m - offset])
 Get a part of a column of a matrix. More...
 
matrix_t matrix_get_max_elem_in_column (uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t col_num)
 Get the largest element of a column vector in a matrix. More...
 
matrix_t matrix_get_abs_max_elem_in_column (uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t col_num)
 Get the maximum absolute value of a column vector in a matrix. More...
 
matrix_t matrix_get_max_elem_in_part_column (uint8_t max_m, uint8_t max_n, matrix_t matrix[max_m][max_n], uint8_t row_num, uint8_t col_num)
 Get the largest element of a column vector in a sub-matrix. More...
 
matrix_t matrix_get_abs_max_elem_in_part_column (uint8_t max_m, uint8_t max_n, matrix_t matrix[max_m][max_n], uint8_t row_num, uint8_t col_num)
 Get the maximum absolute value of a column vector in a sub-matrix. More...
 
matrix_t matrix_get_abs_max_elem_and_index_in_part_column (uint8_t max_m, uint8_t max_n, matrix_t matrix[max_m][max_n], uint8_t row_num, uint8_t col_num, uint8_t *index)
 Get the maximum absolute value and its position in a column vector in a sub-matrix. More...
 
void matrix_swap_rows (uint8_t n, matrix_t matrix[][n], uint8_t i, uint8_t j)
 Swaps two rows of a matrix. More...
 
void matrix_part_swap_rows (uint8_t n, matrix_t matrix[][n], uint8_t i, uint8_t j, uint8_t col_begin, uint8_t col_end)
 Swaps two rows of a sub-matrix. More...
 
double matrix_get_two_norm (uint8_t m, uint8_t n, matrix_t A[][n])
 Get the 2-norm of a matrix that is equal to the largest singular value. More...
 
double matrix_get_frob_norm (uint8_t m, uint8_t n, matrix_t A[][n])
 Get the Frobenius norm of a matrix. More...
 
void matrix_get_inv_upp_triang (uint8_t m, uint8_t n, matrix_t U[][n], matrix_t inv_U[][m])
 Computes the inverse an upper triangular matrix. More...
 
void matrix_get_inv_low_triang (uint8_t m, uint8_t n, matrix_t L[][n], matrix_t inv_L[][m])
 Computes the inverse a lower triangular matrix. More...
 
void matrix_get_upp_triang (uint8_t m, uint8_t n, matrix_t A[][n], matrix_t tr_up_A[][n])
 Gets the upper triangular part of a matrix. More...
 
void matrix_get_low_triang (uint8_t m, uint8_t n, matrix_t A[][n], matrix_t tr_low_A[][n])
 Gets the lower triangular part of a matrix. More...
 
void matrix_print (uint8_t m, uint8_t n, matrix_t matrix[m][n])
 Display the values of the matrix elements. More...
 
void matrix_part_print (uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t start_row_ind, uint8_t end_row_ind, uint8_t start_col_ind, uint8_t end_col_ind)
 Display the values of the sub-matrix elements. More...
 
void matrix_flex_print (uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t before_dec, uint8_t after_dec)
 Display the values of the matrix elements. More...
 
void matrix_flex_part_print (uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t start_row_ind, uint8_t end_row_ind, uint8_t start_col_ind, uint8_t end_col_ind, uint8_t before_dot, uint8_t after_dot)
 Display the values of the sub-matrix elements. More...
 
void matrix_part_mul_scalar_vec_matr (uint8_t max_m, uint8_t max_n, matrix_t scalar, matrix_t vec[max_m], matrix_t matrix[max_m][max_n], uint8_t begin_row, uint8_t begin_column, matrix_t dst_arr[max_n - begin_row])
 Compute the multiplication of a scalar with row vector and a sub-matrix. More...
 
matrix_t matrix_read (uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t i, uint8_t j)
 Get the value of a matrix at the position (i,j). More...
 
void matrix_write (uint8_t m, uint8_t n, matrix_t matrix[m][n], uint8_t i, uint8_t j, matrix_t val)
 Write a value in a matrix at the position (i,j). More...
 

Detailed Description

Matrix computations.

Matrix computations include operations such as addition, subtraction, and transposition.

Author
Zakaria Kasmi zkasm.nosp@m.i@in.nosp@m.f.fu-.nosp@m.berl.nosp@m.in.de

Definition in file matrix.h.

Macro Definition Documentation

◆ M_PI

#define M_PI   3.14159265358979323846

Pi, the ratio of a circle's circumference to its diameter.

Definition at line 54 of file matrix.h.

◆ MACHEPS

#define MACHEPS   2E-16

The upper bound on the relative error due to rounding in floating point arithmetic.

Definition at line 46 of file matrix.h.

◆ matrix_t

#define matrix_t   double

Define the data type of the matrix elements.

The user can choose between a double or floating point arithmetic.

Definition at line 38 of file matrix.h.

Function Documentation

◆ matrix_add()

void matrix_add ( uint8_t  m,
uint8_t  n,
matrix_t  A[m][n],
matrix_t  B[m][n],
matrix_t  A_plus_B[m][n] 
)

Compute the addition of two matrices.

Add matrix B to matrix A and return the result in A_plus_B matrix.

Parameters
[in]mrow number of the matrix to add.
[in]ncolumn number of the matrix to add.
[in]A[][]pointer to the first matrix.
[in]B[][]pointer to the second matrix.
[out]A_plus_B[][]pointer to the destination matrix.

Definition at line 341 of file matrix.c.

Referenced by matrix_test().

◆ matrix_add_to_diag()

void matrix_add_to_diag ( uint8_t  n,
matrix_t  A[][n],
uint8_t  diag_el_num,
matrix_t  value 
)

Add a number to diagonal elements of a matrix.

Parameters
[in]ncolumn number of the matrix.
[in,out]A[][]pointer to the matrix.
[in]diag_el_numnumber of diagonal elements to overwrite.
[in]valuethe value to add to the diagonal elements.

Definition at line 353 of file matrix.c.

Referenced by opt_levenberg_marquardt(), and opt_levenberg_marquardt_correction().

◆ matrix_clear()

void matrix_clear ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n] 
)

Clear all the elements of the vector.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[out]matrix[][]pointer to the matrix.

Definition at line 46 of file matrix.c.

Referenced by dist_based_jacobian_get_JTJ(), householder_test(), matrix_get_diag_mat(), matrix_get_diag_mat_new(), matrix_get_inv_low_triang(), matrix_get_inv_upp_triang(), and qr_givens_decomp().

◆ matrix_copy()

void matrix_copy ( uint8_t  m,
uint8_t  n,
matrix_t  src_matrix[m][n],
matrix_t  dest_matrix[m][n] 
)

Copy the elements of a matrix to another matrix.

Parameters
[in]mrow number of the matrix to copy.
[in]ncolumn number of the matrix to copy.
[in]src_matrix[][]pointer to the source matrix
[out]dest_matrix[][]pointer to the destination matrix.

Definition at line 83 of file matrix.c.

References matrix_t.

Referenced by givens_test(), householder_test(), matrix_get_two_norm(), solve_big_matrix_test(), solve_test(), and triangular_matrices_test().

◆ matrix_flex_part_print()

void matrix_flex_part_print ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
uint8_t  start_row_ind,
uint8_t  end_row_ind,
uint8_t  start_col_ind,
uint8_t  end_col_ind,
uint8_t  before_dot,
uint8_t  after_dot 
)

Display the values of the sub-matrix elements.

This function allows the user to determine the precision as well as the with of the numbers to display.

Note
This function is more memory-consuming than matrix_part_print.
Parameters
[in]mtotal row number of the matrix.
[in]ntotal column number of the matrix.
[in]matrix[][]pointer to the entire matrix.
[in]start_row_indstart row number of the sub-matrix.
[in]end_row_indend row number of the sub-matrix.
[in]start_col_indstart column number of the sub-matrix.
[in]end_col_indend column number of the sub-matrix.
[in]before_dotthe number of digits to be printed before the decimal point.
[in]after_dotthe number of digits to be printed after the decimal point.

Definition at line 247 of file matrix.c.

References utils_printf().

Referenced by matrix_test().

◆ matrix_flex_print()

void matrix_flex_print ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
uint8_t  before_dec,
uint8_t  after_dec 
)

Display the values of the matrix elements.

This function allows the user to determine the precision as well as the with of the numbers to display.

Note
This function is more memory-consuming than matrix_print.
Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]matrix[][]pointer to the entire matrix.
[in]before_decthe number of digits to be printed before the decimal point.
[in]after_decthe number of digits to be printed after the decimal point.

Definition at line 220 of file matrix.c.

References utils_printf().

Referenced by givens_test(), householder_test(), inv_triangular_matrices_test(), lu_decomp_test(), matrix_test(), moore_penrose_pinv_compute_print(), optimization_test(), pos_algos_common_test(), solve_big_matrix_test(), solve_test(), and triangular_matrices_test().

◆ matrix_get_abs_max_elem_and_index_in_part_column()

matrix_t matrix_get_abs_max_elem_and_index_in_part_column ( uint8_t  max_m,
uint8_t  max_n,
matrix_t  matrix[max_m][max_n],
uint8_t  row_num,
uint8_t  col_num,
uint8_t *  index 
)

Get the maximum absolute value and its position in a column vector in a sub-matrix.

Parameters
[in]max_mtotal row number of the matrix.
[in]max_ntotal column number of the matrix.
[in]matrix[][]pointer to the entire matrix.
[in]row_numrow number of the sub-matrix.
[in]col_numcolumn number of the sub-matrix.
[out]indexpointer to the variable holding the position of the maximum absolute value in the column vector of the sub-matrix.
Returns
the maximum absolute value of a partial column.

Definition at line 703 of file matrix.c.

References matrix_t.

Referenced by lu_decomp().

◆ matrix_get_abs_max_elem_in_column()

matrix_t matrix_get_abs_max_elem_in_column ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
uint8_t  col_num 
)

Get the maximum absolute value of a column vector in a matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]matrix[][]pointer to the matrix.
[in]col_numcolumn number.
Returns
the maximum absolute value of a column.

Definition at line 651 of file matrix.c.

References matrix_t.

◆ matrix_get_abs_max_elem_in_part_column()

matrix_t matrix_get_abs_max_elem_in_part_column ( uint8_t  max_m,
uint8_t  max_n,
matrix_t  matrix[max_m][max_n],
uint8_t  row_num,
uint8_t  col_num 
)

Get the maximum absolute value of a column vector in a sub-matrix.

Parameters
[in]max_mtotal row number of the matrix.
[in]max_ntotal column number of the matrix.
[in]matrix[][]pointer to the entire matrix.
[in]row_numrow number of the sub-matrix.
[in]col_numcolumn number of the sub-matrix.
Returns
the maximum absolute value of a partial column.

Definition at line 685 of file matrix.c.

References matrix_t.

◆ matrix_get_column_vec()

void matrix_get_column_vec ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
uint8_t  col_num,
matrix_t  col_vec[m] 
)

Get a column of a matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]matrix[][]pointer to the matrix.
[in]col_numnumber of the requested column.
[out]col_vec[]pointer to the column vector.

Definition at line 612 of file matrix.c.

Referenced by matrix_trans_mul_itself().

◆ matrix_get_diag_mat()

void matrix_get_diag_mat ( uint8_t  m,
uint8_t  n,
matrix_t  value,
matrix_t  diag_matrix[m][n] 
)

Create a diagonal matrix with a specified value.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]valuevalue of the diagonal elements.
[in,out]diag_matrix[][]pointer to the diagonal matrix.

Definition at line 594 of file matrix.c.

References matrix_clear(), and matrix_set_diag_elements().

Referenced by lu_decomp(), and matrix_test().

◆ matrix_get_diag_mat_new()

void matrix_get_diag_mat_new ( uint8_t  m,
uint8_t  n,
matrix_t  diag_matrix[m][n],
uint8_t  length,
matrix_t  vec[] 
)

Set all the diagonal elements of a matrix with values that are saved in a vector.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in,out]diag_matrix[][]pointer to the matrix.
[in]lengthsize of the vector.
[in]vecpointer to the vector containing diagonal elements.

Definition at line 581 of file matrix.c.

References matrix_clear().

Referenced by matrix_test().

◆ matrix_get_frob_norm()

double matrix_get_frob_norm ( uint8_t  m,
uint8_t  n,
matrix_t  A[][n] 
)

Get the Frobenius norm of a matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]A[][]pointer to the matrix.
Returns
the Frobenius norm a matrix.

Definition at line 782 of file matrix.c.

Referenced by matrix_test().

◆ matrix_get_inv_low_triang()

void matrix_get_inv_low_triang ( uint8_t  m,
uint8_t  n,
matrix_t  L[][n],
matrix_t  inv_L[][m] 
)

Computes the inverse a lower triangular matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]L[][]pointer to the matrix.
[out]inv_L[][]pointer to the inverse matrix.

Definition at line 817 of file matrix.c.

References matrix_clear(), and matrix_t.

Referenced by inv_triangular_matrices_test(), and solve_lu_decomp().

◆ matrix_get_inv_upp_triang()

void matrix_get_inv_upp_triang ( uint8_t  m,
uint8_t  n,
matrix_t  U[][n],
matrix_t  inv_U[][m] 
)

Computes the inverse an upper triangular matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]U[][]pointer to the upper triangular matrix.
[out]inv_U[][]pointer to the inverse matrix.

Definition at line 795 of file matrix.c.

References matrix_clear(), and matrix_t.

Referenced by inv_triangular_matrices_test().

◆ matrix_get_low_triang()

void matrix_get_low_triang ( uint8_t  m,
uint8_t  n,
matrix_t  A[][n],
matrix_t  tr_low_A[][n] 
)

Gets the lower triangular part of a matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]A[][]pointer to the matrix.
[out]tr_low_A[][]pointer to the lower triangular part of the matrix.

Definition at line 868 of file matrix.c.

Referenced by triangular_matrices_test().

◆ matrix_get_max_elem_in_column()

matrix_t matrix_get_max_elem_in_column ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
uint8_t  col_num 
)

Get the largest element of a column vector in a matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]matrix[][]pointer to the matrix.
[in]col_numcolumn number.
Returns
the largest element of a column.

Definition at line 635 of file matrix.c.

References matrix_t.

◆ matrix_get_max_elem_in_part_column()

matrix_t matrix_get_max_elem_in_part_column ( uint8_t  max_m,
uint8_t  max_n,
matrix_t  matrix[max_m][max_n],
uint8_t  row_num,
uint8_t  col_num 
)

Get the largest element of a column vector in a sub-matrix.

Parameters
[in]max_mtotal row number of the matrix.
[in]max_ntotal column number of the matrix.
[in]matrix[][]pointer to the entire matrix.
[in]row_numrow number of the sub-matrix.
[in]col_numcolumn number of the sub-matrix.
Returns
the largest element of a partial column.

Definition at line 668 of file matrix.c.

References matrix_t.

◆ matrix_get_part_column_vec()

void matrix_get_part_column_vec ( uint8_t  max_m,
uint8_t  max_n,
matrix_t  matrix[max_m][max_n],
uint8_t  col_num,
uint8_t  offset,
matrix_t  col_vec[max_m - offset] 
)

Get a part of a column of a matrix.

Parameters
[in]max_mrow number of the matrix.
[in]max_ncolumn number of the matrix.
[in]matrix[][]pointer to the matrix.
[in]col_numnumber of the requested column.
[in]offsetpoints to the start position of the column vector.
[out]col_vec[]pointer to the column vector.

Definition at line 623 of file matrix.c.

◆ matrix_get_rank()

uint8_t matrix_get_rank ( uint8_t  m,
uint8_t  n,
matrix_t  singl_values_arr[],
uint8_t  length 
)

Compute the rank of a matrix.

The SVD must be previously invoked to get the singular values of the matrix.

Note
This function should be invoked after the call of the svd method.
Parameters
[in]mrow number of the source matrix.
[in]ncolumn number of the source matrix.
[in]singl_values_arr[]array containing the singular values of the matrix.
[in]lengthlength of the singular values array.
Returns
the rank of the matrix.

Definition at line 312 of file matrix.c.

Referenced by trilateration_get_rank_and_homogeneous_solution().

◆ matrix_get_two_norm()

double matrix_get_two_norm ( uint8_t  m,
uint8_t  n,
matrix_t  A[][n] 
)

Get the 2-norm of a matrix that is equal to the largest singular value.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]A[][]pointer to the matrix.
Returns
the 2-norm of a matrix.

Definition at line 752 of file matrix.c.

References matrix_dim_t::col_num, matrix_copy(), matrix_print(), matrix_t, matrix_dim_t::row_num, svd(), svd_get_single_values_num(), and svd_get_U_dim().

Referenced by matrix_test().

◆ matrix_get_upp_triang()

void matrix_get_upp_triang ( uint8_t  m,
uint8_t  n,
matrix_t  A[][n],
matrix_t  tr_up_A[][n] 
)

Gets the upper triangular part of a matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]A[][]pointer to the matrix.
[out]tr_up_A[][]pointer to the upper triangular part of the matrix.

Definition at line 841 of file matrix.c.

Referenced by qr_givens_decomp(), and triangular_matrices_test().

◆ matrix_in_place_transpose()

void matrix_in_place_transpose ( uint8_t  m,
matrix_t  matrix[][m] 
)

Computes the in-place transpose of a matrix.

Transpose the matrix without auxiliary memory.

Note
This function is limited to square matrices.
Parameters
[in]mrow and column number of the matrix.
[in,out]matrix[][]pointer to the matrix to transpose.

Definition at line 69 of file matrix.c.

References matrix_t.

◆ matrix_init()

void matrix_init ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
matrix_t  value 
)

Initialize all the elements of the matrix with a specified value.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[out]matrix[][]pointer to the matrix.
[in]valuevalue to be set.

Definition at line 51 of file matrix.c.

◆ matrix_mul()

void matrix_mul ( uint8_t  a_line_num,
uint8_t  a_col_num,
matrix_t  a_matrix[a_line_num][a_col_num],
uint8_t  b_line_num,
uint8_t  b_col_num,
matrix_t  b_matrix[b_line_num][b_col_num],
matrix_t  dest_matrix[a_line_num][b_col_num] 
)

Compute the multiplication of two matrices.

Parameters
[in]a_line_numrow number of the first matrix.
[in]a_col_numcolumn number of the first matrix.
[in]a_matrix[][]pointer to the first matrix.
[in]b_line_numrow number of the second matrix.
[in]b_col_numcolumn number of the second matrix.
[in]b_matrix[][]pointer to the second matrix.
[out]dest_matrix[][]pointer to the destination matrix.

Definition at line 363 of file matrix.c.

Referenced by get_PDOP(), matrix_test(), and solve_lu_decomp().

◆ matrix_mul_col_vec_row_vec()

void matrix_mul_col_vec_row_vec ( uint8_t  m,
matrix_t  col_vec[m],
uint8_t  n,
matrix_t  row_vec[n],
uint8_t  max_n,
matrix_t  res_mat[][max_n] 
)

Compute the multiplication of a column and row vector.

Return Cm,1 * R1,n = Mm,n, where C is a m-dimensional column vector, R is a n-dimensional row vector, and the result is a (mxn)-matrix.

Parameters
[in]mrow number of the column vector.
[in]col_vec[]pointer to the column vector.
[in]ncolumn number of the row vector.
[in]row_vec[]pointer to the row vector.
[in]max_ncolumn number of the result matrix.
[out]res_mat[][]pointer to the (mxn) result matrix.

Definition at line 531 of file matrix.c.

◆ matrix_mul_scalar()

void matrix_mul_scalar ( uint8_t  m,
uint8_t  n,
matrix_t  mat_src[m][n],
matrix_t  value,
matrix_t  mat_dest[m][n] 
)

Multiply all elements of a matrix with a specified value.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]mat_srcpointer to the source matrix.
[in]valuemultiplication factor.
[out]mat_dest[][]pointer to the destination matrix.

Definition at line 602 of file matrix.c.

Referenced by loc_levenberg_marquardt(), loc_levenberg_marquardt_correction(), opt_levenberg_marquardt(), and opt_levenberg_marquardt_correction().

◆ matrix_mul_scalar_vec_matr()

void matrix_mul_scalar_vec_matr ( uint8_t  m,
uint8_t  n,
matrix_t  scalar,
matrix_t  vec[m],
matrix_t  matrix[m][n],
matrix_t  dst_arr[n] 
)

Compute the multiplication of a scalar with row vector and a matrix.

Return scal*R1,m * Am,n = R1,n, where scal is a scalar, R is a m-dimensional row vector, A is a (mxn)-matrix, and the result is a row vector of n-dimension.

Parameters
[in]msize of the row vector and row number of the matrix.
[in]ncolumn number of the matrix.
[in]scalarscalar value.
[in]vec[]pointer to the row vector.
[in]matrix[][]pointer to the matrix.
[out]dst_arrpointer to the destination row vector of n-dimension.

Definition at line 470 of file matrix.c.

References matrix_t.

◆ matrix_mul_vec()

void matrix_mul_vec ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
matrix_t  vec[n],
matrix_t  dst_arr[m] 
)

Compute the multiplication of a matrix with a column vector.

Return Am,n * Vn,1 = Bm,1, where the A is a (mxn)-matrix, V is a n-dimensional column vector, and the result is a m-dimensional column vector.

Parameters
[in]mrow number of the matrix to multiply.
[in]ncolumn number of the matrix to multiply.
[in]matrix[][]pointer to the matrix.
[in]vecpointer to the n-dimensional column vector.
[out]dst_arrpointer to the destination m-dimensional column vector.

Definition at line 434 of file matrix.c.

References matrix_t.

Referenced by get_delta_x(), loc_gauss_newton(), modified_gauss_newton(), newton_raphson(), opt_levenberg_marquardt_correction(), solve(), solve_lu_decomp(), solve_test(), and trilateration_get_particular_solution().

◆ matrix_part_copy()

void matrix_part_copy ( uint8_t  m,
uint8_t  n,
matrix_t  src_matrix[m][n],
uint8_t  start_row_ind,
uint8_t  end_row_ind,
uint8_t  start_col_ind,
uint8_t  end_col_ind,
uint8_t  dest_row_num,
uint8_t  dest_col_num,
matrix_t  dest_matrix[][dest_col_num] 
)

Copy a part of a matrix to another matrix or sub-matrix.

A part of the source matrix can be copied in a sub-part of the destination matrix (sub-matrix). The source and destination sub-matrices are limited by the row and column indices.

Parameters
[in]mrow number of the source matrix.
[in]ncolumn number of the source matrix.
[in]src_matrix[][]pointer to the source matrix.
[in]start_row_indthe start index of the rows of the source sub-matrix.
[in]end_row_indthe end index of the rows of the source sub-matrix.
[in]start_col_indthe start index of the columns of the source sub-matrix.
[in]end_col_indthe end index of the columns of the source sub-matrix.
[in]dest_row_numthe row number of the destination sub-matrix.
[in]dest_col_numthe column number of the destination sub-matrix.
[out]dest_matrix[][]pointer to the destination (sub)-matrix.

Definition at line 89 of file matrix.c.

Referenced by qr_common_get_reduced_QR(), and qr_givens_decomp().

◆ matrix_part_mul()

void matrix_part_mul ( uint8_t  a_col_num_max,
matrix_t  a_matrix[][a_col_num_max],
uint8_t  b_col_num_max,
matrix_t  b_matrix[][b_col_num_max],
uint8_t  a_start_row_ind,
uint8_t  a_end_row_ind,
uint8_t  a_start_col_ind,
uint8_t  a_end_col_ind,
uint8_t  b_start_row_ind,
uint8_t  b_end_row_ind,
uint8_t  b_start_col_ind,
uint8_t  b_end_col_ind,
uint8_t  dest_col_size,
matrix_t  dest_matrix[][dest_col_size] 
)

Compute the partial multiplication of two matrices.

Enables the calculation of matrix product of parts of two matrices.

Parameters
[in]a_col_num_maxcolumn number of the first matrix.
[in]a_matrix[][]pointer to the first matrix.
[in]b_col_num_maxcolumn number of the second matrix.
[in]b_matrix[][]pointer to the second matrix.
[in]a_start_row_indrow begin of the first, partial matrix.
[in]a_end_row_indrow end of the first, partial matrix.
[in]a_start_col_indcolumn begin of the first, partial matrix.
[in]a_end_col_indcolumn end of the first, partial matrix.
[in]b_start_row_indrow begin of the second, partial matrix.
[in]b_end_row_indrow end of the second, partial matrix.
[in]b_start_col_indcolumn begin of the second, partial matrix.
[in]b_end_col_indcolumn end of the second, partial matrix.
[in]dest_col_sizecolumn size of the destination matrix.
[out]dest_matrix[][]pointer to the destination matrix.

Definition at line 391 of file matrix.c.

Referenced by matrix_test().

◆ matrix_part_mul_scalar_vec_matr()

void matrix_part_mul_scalar_vec_matr ( uint8_t  max_m,
uint8_t  max_n,
matrix_t  scalar,
matrix_t  vec[max_m],
matrix_t  matrix[max_m][max_n],
uint8_t  begin_row,
uint8_t  begin_column,
matrix_t  dst_arr[max_n - begin_row] 
)

Compute the multiplication of a scalar with row vector and a sub-matrix.

Return scal*R1,m * Am,n = R1,n, where scal is a scalar, R is a m-dimensional row vector, A is a (mxn)-matrix, and the result is a row vector of n-dimension.

Parameters
[in]max_msize of the row vector and row number of the matrix.
[in]max_ncolumn number of the matrix.
[in]scalarscalar value.
[in]vec[]pointer to the row vector.
[in]matrix[][]pointer to the matrix.
[in]begin_rowstart row number of the sub-matrix.
[in]begin_columnstart column number of the sub-matrix.
[out]dst_arrpointer to the destination row vector of n-dimension.

Definition at line 489 of file matrix.c.

References matrix_t.

◆ matrix_part_print()

void matrix_part_print ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
uint8_t  start_row_ind,
uint8_t  end_row_ind,
uint8_t  start_col_ind,
uint8_t  end_col_ind 
)

Display the values of the sub-matrix elements.

Parameters
[in]mtotal row number of the matrix.
[in]ntotal column number of the matrix.
[in]matrix[][]pointer to the entire matrix.
[in]start_row_indstart row number of the sub-matrix.
[in]end_row_indend row number of the sub-matrix.
[in]start_col_indstart column number of the sub-matrix.
[in]end_col_indend column number of the sub-matrix.

Definition at line 164 of file matrix.c.

◆ matrix_part_swap_rows()

void matrix_part_swap_rows ( uint8_t  n,
matrix_t  matrix[][n],
uint8_t  i,
uint8_t  j,
uint8_t  col_begin,
uint8_t  col_end 
)

Swaps two rows of a sub-matrix.

Swaps the rows i and j of a part of a matrix.

Parameters
[in]ncolumn number of the entire matrix.
[in,out]matrix[][]pointer to the entire matrix.
[in]ithe i-the row of the sub-matrix.
[in]jthe j-the row of the sub-matrix.
[in]col_beginthe column begin of the sub-matrix.
[in]col_endthe column end of the sub-matrix.

Definition at line 736 of file matrix.c.

References matrix_t.

Referenced by lu_decomp().

◆ matrix_print()

void matrix_print ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n] 
)

Display the values of the matrix elements.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]matrix[][]pointer to the entire matrix.

Definition at line 141 of file matrix.c.

Referenced by matrix_get_two_norm(), and svd_compute_print_U_S_V_s().

◆ matrix_read()

matrix_t matrix_read ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
uint8_t  i,
uint8_t  j 
)

Get the value of a matrix at the position (i,j).

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]matrix[][]pointer to the matrix.
[in]irow number.
[in]jcolumn number.
Returns
the value of the matrix at the row i and column j.

Definition at line 895 of file matrix.c.

◆ matrix_set_diag_elements()

void matrix_set_diag_elements ( uint8_t  m,
uint8_t  n,
matrix_t  value,
matrix_t  diag_matrix[m][n] 
)

Set all the diagonal elements of a matrix with a specified value.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]valuevalue to be set.
[in,out]diag_matrix[][]pointer to the matrix.

Definition at line 565 of file matrix.c.

Referenced by matrix_get_diag_mat().

◆ matrix_sub()

void matrix_sub ( uint8_t  m,
uint8_t  n,
matrix_t  A[m][n],
matrix_t  B[m][n],
matrix_t  A_minus_B[m][n] 
)

Compute the subtraction of two matrices.

Subtract matrix B from matrix A and return the result in A_minus_B matrix.

Parameters
[in]mrow number of the matrix to add.
[in]ncolumn number of the matrix to add.
[in]A[][]pointer to the first matrix.
[in]B[][]pointer to the second matrix.
[out]A_minus_B[][]pointer to the destination matrix.

Definition at line 329 of file matrix.c.

Referenced by matrix_test().

◆ matrix_swap_rows()

void matrix_swap_rows ( uint8_t  n,
matrix_t  matrix[][n],
uint8_t  i,
uint8_t  j 
)

Swaps two rows of a matrix.

Swaps the rows i and j of a matrix.

Parameters
[in]ncolumn number of the matrix.
[in]matrix[][]pointer to the matrix.
[in]ithe i-the row of the matrix.
[in]jthe j-the row of the matrix.

Definition at line 725 of file matrix.c.

References matrix_t.

Referenced by lu_decomp(), and matrix_test().

◆ matrix_trans_mul_itself()

void matrix_trans_mul_itself ( uint8_t  m,
uint8_t  n,
matrix_t  A[m][n],
matrix_t  AT_mul_A[n][n] 
)

Compute the multiplication of the transpose of a matrix with itself.

Transpose the matrix A and multiply it with the matrix A: A'*A.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]A[][]pointer to the matrix.
[out]AT_mul_A[][]pointer to the destination matrix (A'*A).

Definition at line 545 of file matrix.c.

References matrix_get_column_vec(), and matrix_t.

Referenced by magnetic_based_jacobian_get_JTJ(), modified_gauss_newton(), opt_levenberg_marquardt(), and opt_levenberg_marquardt_correction().

◆ matrix_trans_mul_vec()

void matrix_trans_mul_vec ( uint8_t  m,
uint8_t  n,
matrix_t  A[m][n],
uint8_t  b_size,
matrix_t  b_vec[m],
matrix_t  c_vec[n] 
)

Compute the multiplication of transposed matrix with column vector.

Transpose A and return A'n,m * Vm,1 = Bn,1, where A is a (mxn)-matrix, V is a m-dimensional column vector, and the result is a n-dimensional column vector.

Parameters
[in]mrow number of the matrix to transpose and multiply.
[in]ncolumn number of the matrix to transpose and multiply.
[in]A[][]pointer to the matrix.
[in]b_sizesize of the column vector.
[in]b_vec[]pointer to the column vector of m-dimension.
[out]c_vec[]pointer to the destination, column vector of n-dimension.

Definition at line 511 of file matrix.c.

Referenced by magnetic_based_jacobian_get_JTf(), modified_gauss_newton(), opt_levenberg_marquardt(), opt_levenberg_marquardt_correction(), solve_givens(), and solve_householder().

◆ matrix_transpose()

void matrix_transpose ( uint8_t  m,
uint8_t  n,
matrix_t  src_matrix[m][n],
matrix_t  dest_matrix[n][m] 
)

Computes the transpose of a matrix.

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[in]src_matrix[][]pointer to the matrix to transpose.
[out]dest_matrix[][]pointer to the destination matrix.

Definition at line 56 of file matrix.c.

Referenced by get_PDOP(), matrix_test(), moore_penrose_get_pinv(), and triangular_matrices_test().

◆ matrix_vec_mul_matr()

void matrix_vec_mul_matr ( uint8_t  m,
uint8_t  n,
matrix_t  vec[m],
matrix_t  matrix[m][n],
matrix_t  dst_arr[n] 
)

Compute the multiplication of row vector and a matrix.

Return R1,m * Am,n = R1,n, where R is a m-dimensional row vector, A is a (mxn)-matrix, and the result is a row vector of n-dimension.

Parameters
[in]msize of the row vector and row number of the matrix.
[in]ncolumn number of the matrix.
[in]vec[]pointer to the row vector.
[in]matrix[][]pointer to the matrix.
[out]dst_arrpointer to the destination row vector of n-dimension.

Definition at line 452 of file matrix.c.

References matrix_t.

◆ matrix_write()

void matrix_write ( uint8_t  m,
uint8_t  n,
matrix_t  matrix[m][n],
uint8_t  i,
uint8_t  j,
matrix_t  val 
)

Write a value in a matrix at the position (i,j).

Parameters
[in]mrow number of the matrix.
[in]ncolumn number of the matrix.
[out]matrix[][]pointer to the matrix.
[in]irow number.
[in]jcolumn number.
[in]valvalue to write in the matrix.

Definition at line 901 of file matrix.c.