Robotran C Documentation
Macros | Functions
mbs_matrix.c File Reference
#include <errno.h>
#include <float.h>
#include <limits.h>
#include "mbs_matrix.h"
#include "mbs_path.h"
#include "useful_functions.h"
#include "mbs_errors_names.h"
#include "mbs_message.h"
#include "mbs_define.h"

Macros

#define MSG_ERR   ">> MATRIX>>"
 
#define MSG_PRE   ">> >>"
 

Functions

void transpose (double M[4][4], double Mt[4][4])
 Compute the transpose of a matrix with first index is 1. More...
 
void dot_3x3_arr (double res[3], double mat[3][3], double vec[3])
 Compute the dot product of a matrix by a vector. More...
 
double * dot_3x3_ptr (double *res, double **mat, double *vec)
 Compute the dot product of a matrix by a vector. More...
 
void dot_4x4_arr (double res[4], double mat[4][4], double vec[4])
 Compute the dot product of a matrix by a vector. More...
 
double * dot_4x4_ptr (double *res, double **mat, double *vec)
 Compute the dot product of a matrix by a vector. More...
 
double * dot_nxm_ptr_0 (double *res, double **mat, double *vec, int nr, int nc)
 Compute the dot product of a matrix by a vector. More...
 
double * dot_nxm_ptr_1 (double *res, double **mat, double *vec, int nr, int nc)
 Compute the dot product of a matrix by a vector. More...
 
void matrix_product (double M[4][4], double v[4], double Mv[4])
 
void matrix_product_0 (double **M, double *v, double *Mv, int nr, int nc)
 
void matrix_product_1 (double **M, double *v, double *v_out, int nr, int nc)
 
void matmul_3x3_arr (double res[3][3], double mat_1[3][3], double mat_2[3][3])
 Compute the product of two matrices. More...
 
double ** matmul_3x3_ptr (double **res, double **mat_1, double **mat_2)
 Compute the product of two matrices. More...
 
void matmul_4x4_arr (double res[4][4], double mat_1[4][4], double mat_2[4][4])
 Compute the product of two matrices. More...
 
double ** matmul_4x4_ptr (double **res, double **mat_1, double **mat_2)
 Compute the product of two matrices. More...
 
void doublematrix_product (double M1[4][4], double M2[4][4], double M[4][4])
 DEPRECATED, see matmul_4x4_arr(). More...
 
void doublematrix_product_0 (double **M1, int nb_row_M1, int nb_col_M1, double **M2, int nb_col_M2, double **M)
 Compute the product of two matrices of given shape. The first index is 0. More...
 
void doublematrix_product_1 (double **M1, int nb_row_M1, int nb_col_M1, double **M2, int nb_col_M2, double **M)
 Compute the product of two matrices of given shape. The first index is 1. More...
 
int rotation_matrix (int type, double angle, double R[4][4])
 DEPRECATED, see rotation_matrix_4x4_arr(). More...
 
int rotation_matrix_4x4_arr (int type, double angle, double R[4][4])
 
int rotation_matrix_4x4_ptr (int type, double angle, double **R)
 Compute the rotation matrix for a specified angle around a specific axis. More...
 
int rotation_matrix_3x3_arr (int type, double angle, double R[3][3])
 
int rotation_matrix_3x3_ptr (int type, double angle, double **R)
 Compute the rotation matrix for a specified angle around a specific axis. More...
 
int ** get_imat_0 (int nb_r, int nb_c)
 create (with memory allocation) a [nb_r times nb_c] matrix of integers, starting at index 0. The function returns NULL if the requested number of rows or columns is negative or null. More...
 
int ** get_imat_1 (int nb_r, int nb_c)
 create (with memory allocation) a [nb_r times nb_c] matrix of integers, starting at index 1 More...
 
double ** get_dmat_0 (int nb_r, int nb_c)
 create (with memory allocation) a [nb_r times nb_c] matrix of doubles, starting at index 0 The function returns NULL if the requested number of rows or columns is negative or null. More...
 
double ** get_dmat_1 (int nb_r, int nb_c)
 create (with memory allocation) a [nb_r times nb_c] matrix of doubles, starting at index 1 More...
 
double ** get_contdmat_1 (int nb_r, int nb_c)
 create (with memory allocation) a [nb_r times nb_c] matrix of doubles, starting at index 1. The allocated memory is CONTIGUOUS (adapted for Lapack routine) More...
 
void free_dmat_0 (double **mat)
 release memory for a matrix of doubles, starting at index 0 More...
 
void free_dmat_1 (double **mat)
 release memory for a matrix of doubles, starting at index 1 More...
 
void free_imat_0 (int **mat)
 release memory for a matrix of integers, starting with index 0 More...
 
void free_imat_1 (int **mat)
 release memory for a matrix of integers, starting with index 1 More...
 
void copy_imat_0 (int **tab1, int **tab2, int x, int y)
 Copy the content of a [nb_r times nb_c] matrix of integers to a second matrix, starting with index 0. More...
 
void print_imat_0 (int **mat, int x, int y)
 print a [nb_r times nb_c] matrix of integers in console, starting with index 0 More...
 
void copy_3x3_arr (double res[3][3], double src[3][3])
 Copy the array into another one. More...
 
double ** copy_3x3_ptr (double **res, double **src)
 Copy the matrix into another one. More...
 
void copy_4x4_arr (double res[4][4], double src[4][4])
 Copy the array into another one. More...
 
double ** copy_4x4_ptr (double **res, double **src)
 Copy the matrix into another one. More...
 
void copy_dmat_0 (double **tab_src, double **tab_dest, int nb_r, int nb_c)
 Copy the content of a [nb_r times nb_c] matrix of doubles to a second matrix, starting with index 0. More...
 
void copy_dmat_1 (double **src, double **dest, int x, int y)
 Copy the content of a [x times y] matrix of doubles to a second matrix, starting with index 1. More...
 
double ** re_copy_dmat_0 (double **src, int s_nx, int s_ny, double **dest, int d_nx, int d_ny)
 Copy a 2D array of double into another, reallocate the destination if required. More...
 
double ** re_copy_dmat_1 (double **src, int s_nx, int s_ny, double **dest, int d_nx, int d_ny)
 Copy a 2D array of double into another, reallocate the destination if required. More...
 
void transpose_dmat_0 (double **tab_src, double **tab_dest, int nb_r, int nb_c)
 Transpose a [nb_r times nb_c] matrix of doubles and store the results in a [y times nb_r] matrix, starting with index 0. More...
 
void transpose_dmat_1 (double **tab_src, double **tab_dest, int x, int y)
 Transpose a [x times y] matrix of doubles and store the results in a [y times x] matrix, starting with index 1. More...
 
void print_dmat_0 (double **mat, int nb_r, int nb_c)
 print a [nb_r times nb_c] matrix of doubles in console, starting with index 0 More...
 
void print_format_dmat_0 (double **mat, int nb_r, int nb_c, char *format)
 print a [nb_r times nb_c] matrix of doubles in console, starting with index 0 More...
 
int read_dmat_0 (double **mat, int nb_r, int nb_c, const char *name)
 read a [nb_r times nb_c] matrix of doubles from a file starting with index 0 and store the values in a matrix provided by the user. The first nb_r line of the file are loaded, other lines are ignored. More...
 
double ** load_dmat_0 (int nb_r, int nb_c, char *name)
 load a [nb_r times nb_c] matrix of doubles from a file starting with index 0. The matrix is created (memory allocation) and filled with the values from the file. More...
 
int save_dmat_0 (double **mat, int nb_r, int nb_c, char *name)
 save a [nb_r times nb_c] matrix of doubles to a second matrix, starting with index 0 More...
 
int save_format_dmat_0 (double **mat, int nb_r, int nb_c, char *name, char *format)
 save a [nb_r times nb_c] matrix of doubles to a second matrix, starting with index 0. More...
 
int code_dmat_0 (FILE *file_out, double **values, const char *name, int n_row, int n_col)
 Write C-code to allocate and fill an array of arrays of doubles. More...
 
int code_dmat_1 (FILE *file_out, double **values, const char *name, int n_row, int n_col)
 Write C-code to allocate and fill an array of arrays of doubles. More...
 
int slct_dmat_0 (double **tab_src, int nb_r1, int nb_c1, double **tab_out, int l2, int *vec)
 fill the second [nb_r times l_vec] matrix by selecting the columns of the first [nb_r times nb_c] matrix of doubles. The indexes of the columns are specified in the (l_vec sized) vector, starting with index 0 More...
 
int slctr_dmat_0 (double **tab_src, int nb_r1, int nb_c1, double **tab_out, int l2, int *vec)
 fill the second [l_vec times nb_c] matrix by selecting the rows of the first [nb_r times nb_c] matrix of doubles. The indexes of the rows are specified in the (l_vec sized) vector, starting with index 0 More...
 
void zeros_dmat_0 (double **mat, int nb_r, int nb_c)
 set all the element of a [nb_r times nb_c] matrix of doubles to zero, starting with index 0 More...
 
int set_diag_dmat_0 (double **mat, int size, double value)
 Set a diagonal matrix with the given value. More...
 
double ** identity_dmat_3x3_ptr (double **mat)
 Set the matrix to identity (diagonal to 1, outside to 0). More...
 
double ** identity_dmat_4x4_ptr (double **mat)
 Set the matrix to identity (diagonal to 1, outside to 0). More...
 
int identity_dmat_3x3_arr (double mat[3][3])
 Set the matrix to identity (diagonal to 1, outside to 0). More...
 
int identity_dmat_4x4_arr (double mat[4][4])
 Set the matrix to identity (diagonal to 1, outside to 0). More...
 
int set_identity_dmat_0 (double **mat, int size)
 Set a matrix to identity matrix. Out-of-diagonal elements are set to zero. More...
 
void mult_dmat_0 (double **A, double **B, double **C, int n1, int n2, int n3)
 function to multiply two matrices: A * B = C [n1 n2] [n2 n3] = [n1 n3] More...
 
void sum_dmat_0 (double **A, double **B, double **C, int n1, int n2)
 function to sum two matrices: A + B = C More...
 
void diff_dmat_0 (double **A, double **B, double **C, int n1, int n2)
 function to sum two matrices: A - B = C More...
 
void opposite_dmat_0 (double **A, int n1, int n2)
 function to take the opposite of a given matrix (minus in front of each entry) More...
 
void readmatrix (double **mat, int *n)
 function to read a matrix (obsolete?) More...
 
int get_dmatfiles_size (const char *fileName, int *n_row, int *n_col)
 Function to load a file and calculate the number of rows and columns. More...
 
void update_initzeros (int *initzeros, double **matrix, int *n)
 function to update the initzeros array (obsolete?) More...
 
void arrange_matrix (double **matrix, int *n, int *initzeros)
 function to arrange matrix (obsolete?) More...
 
void scale_matrix (double **matrix, int *n, int *initzeros)
 function to scale matrix (obsolete?) More...
 
void copy_array_dmat_1 (double src[4][4], double **dest)
 Copy the content of an array of doubles to a pointer of matrix, starting with index 1. More...
 
int same_dmat_0 (double **a, double **b, int x, int y)
 Compare if two 2D arrays of floats are the same. More...
 

Detailed Description

The header define functions related to 2D (or more) array operation. This include matrix-vector mixed operations. Some functions are still located in file mbs_utilities.c.

Creation date: 2006

Author
Robotran team

(c) Universite catholique de Louvain

Macro Definition Documentation

◆ MSG_ERR

#define MSG_ERR   ">> MATRIX>>"

◆ MSG_PRE

#define MSG_PRE   ">> >>"

Function Documentation

◆ arrange_matrix()

void arrange_matrix ( double **  matrix,
int *  n,
int *  initzeros 
)

function to arrange matrix (obsolete?)

Parameters
[in,out]matrixthe matrix
[in]nthe vector
[in,out]initzerosthe vector to arrange

◆ code_dmat_0()

int code_dmat_0 ( FILE *  file_out,
double **  values,
const char *  name,
int  n_row,
int  n_col 
)

Write C-code to allocate and fill an array of arrays of doubles.

Parameters
file_outStream in which writing the values.
valuesPointer to the array of arrays to be written (index starts at 0).
nameName of the variable to be filled.
n_rowThe number of rows in the array.
n_colThe number of columns in the array.
Returns
Negative in case of error, 0 if code was generated.

◆ code_dmat_1()

int code_dmat_1 ( FILE *  file_out,
double **  values,
const char *  name,
int  n_row,
int  n_col 
)

Write C-code to allocate and fill an array of arrays of doubles.

Parameters
file_outStream in which writing the values.
valuesPointer to the array of arrays to be written (index starts at 1).
nameName of the variable to be filled.
n_rowThe number of rows in the array (not counting index 0).
n_colThe number of columns in the array (not counting index 0).
Returns
Negative in case of error, 0 if code was generated.

◆ copy_3x3_arr()

void copy_3x3_arr ( double  res[3][3],
double  src[3][3] 
)

Copy the array into another one.

The first index is 0, the dimension of the array is 3x3:

Parameters
[out]resDestination array for the copy.
[in]srcSource array to be copied.

◆ copy_3x3_ptr()

double** copy_3x3_ptr ( double **  res,
double **  src 
)

Copy the matrix into another one.

The first index is 0, the pointer should point to 3 pointers of 3 doubles:

A new matrix is allocated if res is NULL. The memory must be freed by the caller.

Parameters
[out]resDestination pointer for the copy, can be NULL.
[in]srcSource pointer to be copied.
Returns
It return the adress of the copy. This is the argument res except if it was NULL.

◆ copy_4x4_arr()

void copy_4x4_arr ( double  res[4][4],
double  src[4][4] 
)

Copy the array into another one.

The first index is 1, the dimension of the array is 4x4:

The first row and column are copied even if index 1 is supposed to not be used.

Parameters
[out]resDestination array for the copy.
[in]srcSource array to be copied.

◆ copy_4x4_ptr()

double** copy_4x4_ptr ( double **  res,
double **  src 
)

Copy the matrix into another one.

The first index is 1, the pointer should point to 4 pointers of 4 doubles:

The first row and column are copied even if index 1 is supposed to not be used.

A new matrix is allocated if res is NULL. The memory must be freed by the caller.

Parameters
[out]resDestination pointer for the copy, can be NULL.
[in]srcSource pointer to be copied.
Returns
It return the adress of the copy. This is the argument res except if it was NULL.

◆ copy_array_dmat_1()

void copy_array_dmat_1 ( double  src[4][4],
double **  dest 
)

Copy the content of an array of doubles to a pointer of matrix, starting with index 1.

Only the content (inner 3x3 submatrix) is copied. The first row and column are not copied.

Parameters
[in]srcThe array[4][4] of doubles.
[out]destThe pointer to the matrix destination

◆ copy_dmat_0()

void copy_dmat_0 ( double **  tab_src,
double **  tab_dest,
int  nb_r,
int  nb_c 
)

Copy the content of a [nb_r times nb_c] matrix of doubles to a second matrix, starting with index 0.

Parameters
[in]tab_srcthe original matrix of doubles, starting with index 0
[out]tab_destthe copy of tab_src, starting with index 0
[in]nb_rnb of rows
[in]nb_cnb of columns

◆ copy_dmat_1()

void copy_dmat_1 ( double **  src,
double **  dest,
int  x,
int  y 
)

Copy the content of a [x times y] matrix of doubles to a second matrix, starting with index 1.

Parameters
[in]srcthe original matrix of doubles, starting with index 1
[out]destthe copy of tab1, starting with index 1
[in]xnb of rows (without counting the unused first row)
[in]ynb of columns (without counting the unused first column)

◆ copy_imat_0()

void copy_imat_0 ( int **  tab_src,
int **  tab_dest,
int  nb_r,
int  nb_c 
)

Copy the content of a [nb_r times nb_c] matrix of integers to a second matrix, starting with index 0.

Parameters
[in]tab_srcthe original matrix of integer, starting with index 0
[out]tab_destthe copy of tab_src, starting with index 0
[in]nb_rnb of rows
[in]nb_cnb of columns

◆ diff_dmat_0()

void diff_dmat_0 ( double **  A,
double **  B,
double **  C,
int  n1,
int  n2 
)

function to sum two matrices: A - B = C

Parameters
[in]Athe matrix A
[in]Bthe matrix B
[out]Cthe matrix C
[in]n1first size
[in]n2second size

◆ dot_3x3_arr()

void dot_3x3_arr ( double  res[3],
double  mat[3][3],
double  vec[3] 
)

Compute the dot product of a matrix by a vector.

The dimension of the array is 3x3:

The function support in place computation.

Parameters
[in,out]resVector of size 3 such as $ \textbf{res} = \textbf{mat} \overrightarrow{vec} $. It can be the same as vec.
[in]matArray of size 3x3, it will be multiplied by vec.
[in]vecVector of size 3. It can be the same as res.

◆ dot_3x3_ptr()

double* dot_3x3_ptr ( double *  res,
double **  mat,
double *  vec 
)

Compute the dot product of a matrix by a vector.

The first index is 0, the pointer should point to 3 pointers of 3 doubles:

The function support in place computation. A newly allocated array is returned if needed.

Parameters
[in,out]resVector of size 3 such as $ \textbf{res} = \textbf{mat} \overrightarrow{vec} $. It can be the same as vec.
[in]matArray of size 3x3, it will be multiplied by vec.
[in]vecVector of size 3. It can be the same as res.
Returns
It return the adress of the result. This is the argument res except if it was NULL.

◆ dot_4x4_arr()

void dot_4x4_arr ( double  res[4],
double  mat[4][4],
double  vec[4] 
)

Compute the dot product of a matrix by a vector.

The dimension of the array is 4x4:

The function support in place computation.

Parameters
[in,out]resVector of size 4 such as $ \textbf{res} = \textbf{mat} \overrightarrow{vec} $. It can be the same as vec.
[in]matArray of size 4x4, it will be multiplied by vec.
[in]vecVector of size 4. It can be the same as res.

◆ dot_4x4_ptr()

double* dot_4x4_ptr ( double *  res,
double **  mat,
double *  vec 
)

Compute the dot product of a matrix by a vector.

The first index is 1, the pointer should point to 4 pointers of 4 doubles:

The function support in place computation. A newly allocated array is returned if needed.

Parameters
[in,out]resVector of size 4 such as $ \textbf{res} = \textbf{mat} \overrightarrow{vec} $. It can be the same as vec.
[in]matArray of size 4x4, it will be multiplied by vec.
[in]vecVector of size 4. It can be the same as res.
Returns
It return the adress of the result. This is the argument res except if it was NULL.

◆ dot_nxm_ptr_0()

double* dot_nxm_ptr_0 ( double *  res,
double **  mat,
double *  vec,
int  nr,
int  nc 
)

Compute the dot product of a matrix by a vector.

The first index is 0, the sizes must be provided:

The function support in place computation but the caller must ensure that the size of the input vector great enough.

A newly allocated array is returned if the result vector in NULL.

Parameters
[out]resVector of size nr such as $ \textbf{res} = \textbf{mat} \overrightarrow{vec} $. It can be the same as vec (if the latter is big enough).
[in]matArray of size [nr x nc], it will be multiplied by vec.
[in]vecVector of size nc. It can be the same as res.
[in]nrThe number of rows in the matrix; the number of elements in the result.
[in]ncThe number of columns in the matrix; the number of elements in the input vector.
Returns
It return the adress of the result. This is the argument res except if it was NULL.

◆ dot_nxm_ptr_1()

double* dot_nxm_ptr_1 ( double *  res,
double **  mat,
double *  vec,
int  nr,
int  nc 
)

Compute the dot product of a matrix by a vector.

The first index is 1, the sizes must be provided:

The function support in place computation but the caller must ensure that the size of the input vector great enough.

A newly allocated array is returned if the result vector in NULL.

Parameters
[out]resVector of size nr such as $ \textbf{res} = \textbf{mat} \overrightarrow{vec} $. It can be the same as vec (if the latter is big enough).
[in]matArray of size [nr x nc], it will be multiplied by vec.
[in]vecVector of size nc. It can be the same as res.
[in]nrThe number of rows in the matrix; the number of elements in the result.
[in]ncThe number of columns in the matrix; the number of elements in the input vector.
Returns
It return the adress of the result. This is the argument res except if it was NULL.

◆ doublematrix_product()

void doublematrix_product ( double  M1[4][4],
double  M2[4][4],
double  M[4][4] 
)

DEPRECATED, see matmul_4x4_arr().

◆ doublematrix_product_0()

void doublematrix_product_0 ( double **  M1,
int  nb_row_M1,
int  nb_col_M1,
double **  M2,
int  nb_col_M2,
double **  M 
)

Compute the product of two matrices of given shape. The first index is 0.

The memory of the output matrix M must already been allocated. See get_dmat_0() to such matrix creation.

Parameters
[in]M1matrix of size (nb_row_M1 x nb_col_M1).
[in]nb_row_M1number of rows of the matrix M1.
[in]nb_col_M1number of columns of the matrix M1.
[in]M2matrix of size (nb_col_M1 x nb_col_M2).
[in]nb_col_M2number of columns of the matrix M2.
[in,out]Mmatrix of size (nb_row_M1 x nb_col_M2) such as $ \textbf{M} = \textbf{M1} \ \textbf{M2} $.

◆ doublematrix_product_1()

void doublematrix_product_1 ( double **  M1,
int  nb_row_M1,
int  nb_col_M1,
double **  M2,
int  nb_col_M2,
double **  M 
)

Compute the product of two matrices of given shape. The first index is 1.

The memory of the output matrix M must already been allocated. See get_dmat_1() to such matrix creation.

Parameters
[in]M1matrix of size (nb_row_M1 x nb_col_M1) plus first line and row unused.
[in]nb_row_M1number of rows of the matrix M1 (without counting the unused first row/colum).
[in]nb_col_M1number of columns of the matrix M1 (without counting the unused first row/colum).
[in]M2matrix of size (nb_col_M1 x nb_col_M2) plus first line and row unused.
[in]nb_col_M2number of columns of the matrix M2 (without counting the unused first row/colum).
[in,out]MMatrix of size (nb_row_M1 x nb_col_M2) such as $ \textbf{M} = \textbf{M1} \ \textbf{M2} $.

◆ free_dmat_0()

void free_dmat_0 ( double **  mat)

release memory for a matrix of doubles, starting at index 0

Parameters
[out]matmatrix of doubles

◆ free_dmat_1()

void free_dmat_1 ( double **  mat)

release memory for a matrix of doubles, starting at index 1

Parameters
[out]matmatrix of doubles

◆ free_imat_0()

void free_imat_0 ( int **  mat)

release memory for a matrix of integers, starting with index 0

Parameters
[out]matmatrix of integers

◆ free_imat_1()

void free_imat_1 ( int **  mat)

release memory for a matrix of integers, starting with index 1

Parameters
[out]matmatrix of integers

◆ get_contdmat_1()

double** get_contdmat_1 ( int  nb_r,
int  nb_c 
)

create (with memory allocation) a [nb_r times nb_c] matrix of doubles, starting at index 1. The allocated memory is CONTIGUOUS (adapted for Lapack routine)

Parameters
[in]nb_rnb of rows (0 element not taken into account)
[in]nb_cnb of columns (0 element not taken into account)
Returns
requested matrix of doubles

◆ get_dmat_0()

double** get_dmat_0 ( int  nb_r,
int  nb_c 
)

create (with memory allocation) a [nb_r times nb_c] matrix of doubles, starting at index 0 The function returns NULL if the requested number of rows or columns is negative or null.

Parameters
[in]nb_rnb of rows
[in]nb_cnb of columns
Returns
requested matrix of doubles or NULL if nb_r <= 0 OR nb_c <= 0

◆ get_dmat_1()

double** get_dmat_1 ( int  nb_r,
int  nb_c 
)

create (with memory allocation) a [nb_r times nb_c] matrix of doubles, starting at index 1

Parameters
[in]nb_rnb of rows (0 element not taken into account)
[in]nb_cnb of columns (0 element not taken into account)
Returns
requested matrix of doubles

◆ get_dmatfiles_size()

int get_dmatfiles_size ( const char *  fileName,
int *  n_row,
int *  n_col 
)

Function to load a file and calculate the number of rows and columns.

Parameters
[in]fileNameName of the file containing the results to load.
The first column contains the time.
The other columns contain the coordinates.
[in,out]n_rownb of rows
[in,out]n_colnb of columns
Returns
The status:
  • 0: Correct excecution number of rows and cols computed;
  • -1: Unable to open specified file;
  • -2: Empty specified file;
  • -3: At least one argument is a pointer to NULL;

◆ get_imat_0()

int** get_imat_0 ( int  nb_r,
int  nb_c 
)

create (with memory allocation) a [nb_r times nb_c] matrix of integers, starting at index 0. The function returns NULL if the requested number of rows or columns is negative or null.

Parameters
[in]nb_r= nb of rows
[in]nb_c= nb of columns
Returns
requested matrix of integers or NULL if nb_r <= 0 OR nb_c <= 0

◆ get_imat_1()

int** get_imat_1 ( int  nb_r,
int  nb_c 
)

create (with memory allocation) a [nb_r times nb_c] matrix of integers, starting at index 1

Parameters
[in]nb_r= nb of rows (0 element not taken into account)
[in]nb_c= nb of columns (0 element not taken into account)
Returns
requested matrix of integers

◆ identity_dmat_3x3_arr()

int identity_dmat_3x3_arr ( double  mat[3][3])

Set the matrix to identity (diagonal to 1, outside to 0).

The first index is 0, the dimension of the array is 3x3:

Parameters
[in,out]matPointer to the matrix to be set to identity.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE (macro in mbs_hefine.h)

◆ identity_dmat_3x3_ptr()

double** identity_dmat_3x3_ptr ( double **  mat)

Set the matrix to identity (diagonal to 1, outside to 0).

The first index is 0, the pointer should point to 3 pointers of 3 doubles:

A new matrix is allocated if mat is NULL. The memory must be freed by the caller.

Parameters
[in,out]matPointer to the matrix to be set to identity. NULL can be provided.
Returns
It return the adress of the identity matrix. This is the argument mat except if it was NULL.

◆ identity_dmat_4x4_arr()

int identity_dmat_4x4_arr ( double  mat[4][4])

Set the matrix to identity (diagonal to 1, outside to 0).

The first index is 1, the dimension of the array is 4x4:

Parameters
[in,out]matPointer to the matrix to be set to identity.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE (macro in mbs_hefine.h)

◆ identity_dmat_4x4_ptr()

double** identity_dmat_4x4_ptr ( double **  mat)

Set the matrix to identity (diagonal to 1, outside to 0).

The first index is 1, the pointer should point to 4 pointers of 4 doubles:

The first row and column are copied even if index 1 is supposed to not be used.

A new matrix is allocated if res is NULL. The memory must be freed by the caller.

Parameters
[in,out]matPointer to the matrix to be set to identity. NULL can be provided.
Returns
It return the adress of the identity matrix. This is the argument mat except if it was NULL.

◆ load_dmat_0()

double** load_dmat_0 ( int  nb_r,
int  nb_c,
char *  name 
)

load a [nb_r times nb_c] matrix of doubles from a file starting with index 0. The matrix is created (memory allocation) and filled with the values from the file.

Parameters
[in]nb_rnb of rows
[in]nb_cnb of columns
[in]namethe path an name of the file in which loading the matrix

◆ matmul_3x3_arr()

void matmul_3x3_arr ( double  res[3][3],
double  mat_1[3][3],
double  mat_2[3][3] 
)

Compute the product of two matrices.

The dimension of the array is 3x3:

The function support in place computation.

Parameters
[out]resThe results: $ \textbf{res} = \textbf{mat_1} \ \textbf{mat_2} $ (first line and row unused). This can be the same array as mat_1 or mat_2.
[in,out]mat_1Matrix of size 3x3.
[in,out]mat_2Matrix of size 3x3.

◆ matmul_3x3_ptr()

double** matmul_3x3_ptr ( double **  res,
double **  mat_1,
double **  mat_2 
)

Compute the product of two matrices.

The first index is 0, the pointer should point to 3 pointers of 3 doubles:

The function support in place computation.

A new matrix is allocated if res is NULL. The memory must be freed by the caller.

Parameters
[out]resThe results: $ \textbf{res} = \textbf{mat_1} \ \textbf{mat_2} $ (first line and row unused). This can be the same array as mat_1 or mat_2.
[in,out]mat_1Matrix of size 3x3.
[in,out]mat_2Matrix of size 3x3.
Returns
It return the adress of the result. This is the argument res except if it was NULL.

◆ matmul_4x4_arr()

void matmul_4x4_arr ( double  res[4][4],
double  mat_1[4][4],
double  mat_2[4][4] 
)

Compute the product of two matrices.

The first index is 1, the dimension of the array is 4x4:

The function support in place computation.

Parameters
[out]resThe results: $ \textbf{res} = \textbf{mat_1} \ \textbf{mat_2} $ (first line and row unused). This can be the same array as mat_1 or mat_2.
[in,out]mat_1Matrix of size 4x4 with first line and row unused.
[in,out]mat_2Matrix of size 4x4 with first line and row unused.

◆ matmul_4x4_ptr()

double** matmul_4x4_ptr ( double **  res,
double **  mat_1,
double **  mat_2 
)

Compute the product of two matrices.

The first index is 1, the pointer should point to 4 pointers of 4 doubles:

The function support in place computation.

A new matrix is allocated if res is NULL. The memory must be freed by the caller.

Parameters
[out]resThe results: $ \textbf{res} = \textbf{mat_1} \ \textbf{mat_2} $ (first line and row unused). This can be the same array as mat_1 or mat_2.
[in,out]mat_1Matrix of size 4x4.
[in,out]mat_2Matrix of size 4x4.
Returns
It return the adress of the result. This is the argument res except if it was NULL.

◆ matrix_product()

void matrix_product ( double  M[4][4],
double  v[4],
double  Mv[4] 
)

DEPRECATED, see dot_4x4_arr()

◆ matrix_product_0()

void matrix_product_0 ( double **  M,
double *  v,
double *  Mv,
int  nr,
int  nc 
)

DEPRECATED, see dot_ptr_0()

◆ matrix_product_1()

void matrix_product_1 ( double **  M,
double *  v,
double *  v_out,
int  nr,
int  nc 
)

DEPRECATED, see dot_ptr_1()

◆ mult_dmat_0()

void mult_dmat_0 ( double **  A,
double **  B,
double **  C,
int  n1,
int  n2,
int  n3 
)

function to multiply two matrices: A * B = C [n1 n2] [n2 n3] = [n1 n3]

Parameters
[in]Athe matrix A
[in]Bthe matrix B
[out]Cthe matrix C
[in]n1first size
[in]n2second size
[in]n3third size

◆ opposite_dmat_0()

void opposite_dmat_0 ( double **  A,
int  n1,
int  n2 
)

function to take the opposite of a given matrix (minus in front of each entry)

Parameters
[in]Athe matrix A
[in]n1first size
[in]n2second size

◆ print_dmat_0()

void print_dmat_0 ( double **  mat,
int  nb_r,
int  nb_c 
)

print a [nb_r times nb_c] matrix of doubles in console, starting with index 0

call print_format_dmat_0 with default parameter (format = "% -f").

Parameters
[in]matthe matrix to be printed
[in]nb_rnb of rows
[in]nb_cnb of columns

◆ print_format_dmat_0()

void print_format_dmat_0 ( double **  mat,
int  nb_r,
int  nb_c,
char *  format 
)

print a [nb_r times nb_c] matrix of doubles in console, starting with index 0

Parameters
[in]matthe matrix to be printed
[in]nb_rnb of rows
[in]nb_cnb of columns
[in]formatthe chosen format.

◆ print_imat_0()

void print_imat_0 ( int **  mat,
int  nb_r,
int  nb_c 
)

print a [nb_r times nb_c] matrix of integers in console, starting with index 0

Parameters
[in]matthe matrix to be printed
[in]nb_rnb of rows
[in]nb_cnb of columns

◆ re_copy_dmat_0()

double** re_copy_dmat_0 ( double **  src,
int  s_nx,
int  s_ny,
double **  dest,
int  d_nx,
int  d_ny 
)

Copy a 2D array of double into another, reallocate the destination if required.

Parameters
[in]srcSource array to be copied, NULL pointer will free dest.
[in]s_nxSize along axis 0 of the source array, 0 value will free dest.
[in]s_nySize along axis 1 of the source array, 0 value will free dest.
[out]destDestination array to be filled. The array is reallocated if s_nx does not match d_nx. It is allocated if NULL is provided.
[in]d_nxSize along axis 0 of the source array. If 0, dest is reallocated.
[in]d_nySize along axis 1 of the source array. If 0, dest is reallocated.
Returns
NULL if dest has been freed, the pointer to the memory containing the copy. If (re)allocation has occured, the memory is CONTIGUOUS.

◆ re_copy_dmat_1()

double** re_copy_dmat_1 ( double **  src,
int  s_nx,
int  s_ny,
double **  dest,
int  d_nx,
int  d_ny 
)

Copy a 2D array of double into another, reallocate the destination if required.

Parameters
[in]srcSource array to be copied, NULL pointer will free dest.
[in]s_nxSize along axis 0 of the source array.
[in]s_nySize along axis 1 of the source array.
[out]destDestination array to be filled. The array is reallocated if s_nx and s_ny does not match d_nx and d_ny. It is allocated if NULL is provided.
[in]d_nxSize along axis 0 of the source array.
[in]d_nySize along axis 1 of the source array.
Returns
NULL if dest has been freed, the pointer to the memory containing the copy. If (re)allocation has occured, the memory is CONTIGUOUS.

◆ read_dmat_0()

int read_dmat_0 ( double **  mat,
int  nb_r,
int  nb_c,
const char *  name 
)

read a [nb_r times nb_c] matrix of doubles from a file starting with index 0 and store the values in a matrix provided by the user. The first nb_r line of the file are loaded, other lines are ignored.

Parameters
[in]nb_rnb of rows
[in]nb_cnb of columns
[in]namethe path an name of the file in which reading the matrix
[in,out]matallocated array for storing the file
Returns
Error status, <0 in case of failure.

◆ readmatrix()

void readmatrix ( double **  matrix,
int *  n 
)

function to read a matrix (obsolete?)

Parameters
[in,out]matrixthe matrix
[in]nthe vector n

◆ rotation_matrix()

int rotation_matrix ( int  type,
double  angle,
double  R[4][4] 
)

DEPRECATED, see rotation_matrix_4x4_arr().

◆ rotation_matrix_3x3_arr()

int rotation_matrix_3x3_arr ( int  type,
double  angle,
double  R[3][3] 
)

◆ rotation_matrix_3x3_ptr()

int rotation_matrix_3x3_ptr ( int  type,
double  angle,
double **  R 
)

Compute the rotation matrix for a specified angle around a specific axis.

The first index is 0, the dimension of the array is 3x3:

Consider:

  1. O: the original frame;
  2. The rotation around the specified axis;
  3. D: the destination frame;

Then the function returns the matrix $\mathbf{R\_D\_O}$. It allows to pass the coordinates of a vector between frames:

\f\mathbf{vec_D} =$\mathbf{R_D_O}\cdot\mathbf{vec_O} $ \param[in] type integer for axis selection: - $@_fakenl1=\hat{X} $; - $@_fakenl2=\hat{Y} $; - $@_fakenl3=\hat{Z} $; \param[in] angle value of the rotation angle expressed in radians. \param[in,out] R corresponding rotation matrix as an array of size 3x3 with first line and row unused. \return MBS_INFO_SUCCESS or MBS_INFO_FAILURE (invalid axis type). */ int rotation_matrix_3x3_arr(int type, double angle, double R[3][3]); /*! \brief Compute the rotation matrix for a specified angle around a specific axis. The first index is 0, the pointer should point to 3 pointers of 3 doubles: - For array (double R[3][3]) see rotation_matrix_3x3_arr() - For size 4x4 see rotation_matrix_4x4_ptr Consider: 1. `O`: the original frame; 2. The rotation around the specified axis; 3. `D`: the destination frame; Then the function returns the matrix $\mathbf{R_D_O} $. It allows to pass the coordinates of a vector between frames: \f\mathbf{vec\_D} =$\mathbf{R\_D\_O}\cdot\mathbf{vec\_O}$

Parameters
[in]typeinteger for axis selection:
  • $1=\hat{X}$;
  • $2=\hat{Y}$;
  • $3=\hat{Z}$;
[in]anglevalue of the rotation angle expressed in radians.
[in,out]Rcorresponding rotation matrix as pointer of size 3x3 with first line and row unused.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE (invalid axis type).

◆ rotation_matrix_4x4_arr()

int rotation_matrix_4x4_arr ( int  type,
double  angle,
double  R[4][4] 
)

◆ rotation_matrix_4x4_ptr()

int rotation_matrix_4x4_ptr ( int  type,
double  angle,
double **  R 
)

Compute the rotation matrix for a specified angle around a specific axis.

The first index is 1, the dimension of the array is 4x4:

Consider:

  1. O: the original frame;
  2. The rotation around the specified axis;
  3. D: the destination frame;

Then the function returns the matrix $\mathbf{R\_D\_O}$. It allows to pass the coordinates of a vector between frames:

\f\mathbf{vec_D} =$\mathbf{R_D_O}\cdot\mathbf{vec_O} $ \param[in] type integer for axis selection: - $@_fakenl1=\hat{X} $; - $@_fakenl2=\hat{Y} $; - $@_fakenl3=\hat{Z} $; \param[in] angle value of the rotation angle expressed in radians. \param[in,out] R corresponding rotation matrix as an array of size 4x4 with first line and row unused. \return MBS_INFO_SUCCESS or MBS_INFO_FAILURE (invalid axis type). */ int rotation_matrix_4x4_arr(int type, double angle, double R[4][4]); /*! \brief Compute the rotation matrix for a specified angle around a specific axis. The first index is 1, the pointer should point to 4 pointers of 4 doubles: - For array (double R[4][4]) see rotation_matrix_4x4_arr() - For size 3x3 see rotation_matrix_3x3_ptr Consider: 1. `O`: the original frame; 2. The rotation around the specified axis; 3. `D`: the destination frame; Then the function returns the matrix $\mathbf{R_D_O} $. It allows to pass the coordinates of a vector between frames: \f\mathbf{vec\_D} =$\mathbf{R\_D\_O}\cdot\mathbf{vec\_O}$

Parameters
[in]typeinteger for axis selection:
  • $1=\hat{X}$;
  • $2=\hat{Y}$;
  • $3=\hat{Z}$;
[in]anglevalue of the rotation angle expressed in radians.
[in,out]Rcorresponding rotation matrix as pointer of size 4x4 with first line and row unused.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE (invalid axis type).

◆ same_dmat_0()

int same_dmat_0 ( double **  a,
double **  b,
int  x,
int  y 
)

Compare if two 2D arrays of floats are the same.

Parameters
[in]aThe first array, starting with index 0.
[in]bThe second array, starting with index 0.
[in]xThe number of rows.
[in]yThe number of cols.
Returns
1 if arrays are the same, 0 otherwise.

◆ save_dmat_0()

int save_dmat_0 ( double **  mat,
int  nb_r,
int  nb_c,
char *  name 
)

save a [nb_r times nb_c] matrix of doubles to a second matrix, starting with index 0

It call save_format_dmat_0() with default parameter (format = "%12.5e").

More details about the behavior, the parameters and errors in save_format_dmat_0().

Parameters
[in]matthe matrix to save, starting with index 0
[in]nb_rnb of rows
[in]nb_cnb of columns
[in]namethe path and name of the file in which saving the matrix
Returns
Negative in case of error, 0 otherwhise.

◆ save_format_dmat_0()

int save_format_dmat_0 ( double **  mat,
int  nb_r,
int  nb_c,
char *  name,
char *  format 
)

save a [nb_r times nb_c] matrix of doubles to a second matrix, starting with index 0.

The file is open with the option "wt".

The function will create, if missing, the directory for the file.

The value are separated by space, the file ends at the end of the last line of value (no blank final line).

Providing a NULL matrix pointer with null size in both dimension (nb_r, nb_c) write an empty file. Mixing null (NULL or 0) and non-null values generates an error.

Parameters
[in]matthe matrix to save, starting with index 0. Can be NULL if the number of rows and columns are 0.
[in]nb_rNumber of rows, must be positive (or null under conditions).
[in]nb_cNumber of columns, must be positive (or null under conditions).
[in]nameThe path and name of the file in which saving the matrix. The function will try to create the path if needed.
[in]formatThe chosen format to print the datas.
Returns
Negative in case of error, 0 otherwhise.

◆ scale_matrix()

void scale_matrix ( double **  matrix,
int *  n,
int *  initzeros 
)

function to scale matrix (obsolete?)

Parameters
[in,out]matrixthe matrix
[in]nthe vector n
[in,out]initzerosthe vector to arrange

◆ set_diag_dmat_0()

int set_diag_dmat_0 ( double **  mat,
int  size,
double  value 
)

Set a diagonal matrix with the given value.

Out-of-diagonal elements are set to zero.

Parameters
matPointer to the matrix, starting with index 0.
sizeThe size of the matrix.
valueThe value to be set on the diagonal
Returns
MBS_INFO_SUCCESS for success. MBS_INFO_FAILURE for error.

◆ set_identity_dmat_0()

int set_identity_dmat_0 ( double **  mat,
int  size 
)

Set a matrix to identity matrix. Out-of-diagonal elements are set to zero.

Parameters
matPointer to the matrix, starting with index 0.
sizeThe size of the matrix.
Returns
MBS_INFO_SUCCESS for success. Other outputs defined in set_diag_dmat_0(). Negative in case of failure.

◆ slct_dmat_0()

int slct_dmat_0 ( double **  tab_src,
int  nb_r,
int  nb_c,
double **  tab_out,
int  l_vec,
int *  vec 
)

fill the second [nb_r times l_vec] matrix by selecting the columns of the first [nb_r times nb_c] matrix of doubles. The indexes of the columns are specified in the (l_vec sized) vector, starting with index 0

Parameters
[in]tab_srcthe matrix containing the original values of doubles to be sliced
[in]nb_rnb of rows of the matrices
[in]nb_cnb of columns of the first matrix (unused)
[out]tab_outthe sliced matrix such as tab_out[i][j] = tab_src[i][vec[j]], starting with index 0. The matrix have to be already allocated to a sufficient size.
[in]l_vecthe size of the vector vec
[in]vecthe vector containing the indexes of the slices
Returns
0 if no error, -1 if a slice index is over y1, -2 if the slice number is negative.

◆ slctr_dmat_0()

int slctr_dmat_0 ( double **  tab_src,
int  nb_r,
int  nb_c,
double **  tab_dest,
int  l_vec,
int *  vec 
)

fill the second [l_vec times nb_c] matrix by selecting the rows of the first [nb_r times nb_c] matrix of doubles. The indexes of the rows are specified in the (l_vec sized) vector, starting with index 0

Parameters
[in]tab_srcthe matrix containing the original values of doubles to be sliced
[in]nb_rnb of rows of the first matrix (unused)
[in]nb_cnb of columns of the matrices
[out]tab_destthe sliced matrix such as tab_dest[i][j] = tab_src[vec[i]][j], starting with index 0. The matrix have to be already allocated to a sufficient size.
[in]l_vecthe size of the vector vec
[in]vecthe vector containing the indexes of the slices
Returns
0 if no error, -1 if a slice index is over x1, -2 if the slice number is negative.

◆ sum_dmat_0()

void sum_dmat_0 ( double **  A,
double **  B,
double **  C,
int  n1,
int  n2 
)

function to sum two matrices: A + B = C

Parameters
[in]Athe matrix A
[in]Bthe matrix B
[out]Cthe matrix C
[in]n1first size
[in]n2second size

◆ transpose()

void transpose ( double  M[4][4],
double  Mt[4][4] 
)

Compute the transpose of a matrix with first index is 1.

The input and output matrices have unused index 0. See get_dmat_1() to such matrices creation.

Parameters
[in]Mmatrix with first line and row unused.
[in,out]Mtthe transpose of M, index starting at 1.

◆ transpose_dmat_0()

void transpose_dmat_0 ( double **  tab_src,
double **  tab_dest,
int  nb_r,
int  nb_c 
)

Transpose a [nb_r times nb_c] matrix of doubles and store the results in a [y times nb_r] matrix, starting with index 0.

Parameters
[in]tab_srcthe original matrix of doubles, starting with index 0
[out]tab_destthe transpose of tab_src, starting with index 0
[in]nb_rnb of rows of tab_src, nb of columns of tab_dest
[in]nb_cnb of columns of tab_src, nb of rows of tab_dest

◆ transpose_dmat_1()

void transpose_dmat_1 ( double **  tab_src,
double **  tab_dest,
int  x,
int  y 
)

Transpose a [x times y] matrix of doubles and store the results in a [y times x] matrix, starting with index 1.

Parameters
[in]tab1the original matrix of doubles, starting with index 1
[out]tab2the transpose of tab1, starting with index 1
[in]xnb of rows of tab1, nb of columns of tab2 (without counting the unused first row/colum)
[in]ynb of columns of tab1, nb of rows of tab2 (without counting the unused first row/colum)

◆ update_initzeros()

void update_initzeros ( int *  initzeros,
double **  matrix,
int *  n 
)

function to update the initzeros array (obsolete?)

Parameters
[in,out]initzerosthe vector to initialize
[in,out]matrixthe matrix
[in]nthe vector n

◆ zeros_dmat_0()

void zeros_dmat_0 ( double **  mat,
int  nb_r,
int  nb_c 
)

set all the element of a [nb_r times nb_c] matrix of doubles to zero, starting with index 0

Parameters
[in]matthe matrix to be nullified, starting with index 0
[in]nb_rnb of rows
[in]nb_cnb of columns