Zephyr Scientific Library (zscilib)
Functions
Basic Math

Basic mathematical operations for matrices (add, substract, etc.). More...

Functions

int zsl_mtx_add (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc)
 Adds matrices 'ma' and 'mb', assigning the output to 'mc'. Matrices 'ma', 'mb' and 'mc' must all be identically shaped. More...
 
int zsl_mtx_add_d (struct zsl_mtx *ma, struct zsl_mtx *mb)
 Adds matrices 'ma' and 'mb', assigning the output to 'ma'. Matrices 'ma', and 'mb' must be identically shaped. More...
 
int zsl_mtx_sum_rows_d (struct zsl_mtx *m, size_t i, size_t j)
 Adds the values of row 'j' to row 'i' in matrix 'm'. This operation is destructive for row 'i'. More...
 
int zsl_mtx_sum_rows_scaled_d (struct zsl_mtx *m, size_t i, size_t j, zsl_real_t s)
 This function takes the coefficients of row 'j' and multiplies them by scalar 's', then adds the resulting coefficient to the parallel element in row 'i'. Row 'i' will be modified in this operation. More...
 
int zsl_mtx_sub (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc)
 Subtracts matrices 'mb' from 'ma', assigning the output to 'mc'. Matrices 'ma', 'mb' and 'mc' must all be identically shaped. More...
 
int zsl_mtx_sub_d (struct zsl_mtx *ma, struct zsl_mtx *mb)
 Subtracts matrix 'mb' from 'ma', assigning the output to 'ma'. Matrices 'ma', and 'mb' must be identically shaped. More...
 
int zsl_mtx_mult (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc)
 Multiplies matrix 'ma' by 'mb', assigning the output to 'mc'. Matrices 'ma' and 'mb' must be compatibly shaped, meaning that 'ma' must have the same numbers of columns as there are rows in 'mb'. More...
 
int zsl_mtx_mult_d (struct zsl_mtx *ma, struct zsl_mtx *mb)
 Multiplies matrix 'ma' by 'mb', assigning the output to 'ma'. Matrices 'ma' and 'mb' must be compatibly shaped, meaning that 'ma' must have the same numbers of columns as there are rows in 'mb'. To use this function, 'mb' must be a square matrix. This function is destructive. More...
 
int zsl_mtx_scalar_mult_d (struct zsl_mtx *m, zsl_real_t s)
 Multiplies all elements in matrix 'm' by scalar value 's'. More...
 
int zsl_mtx_scalar_mult_row_d (struct zsl_mtx *m, size_t i, zsl_real_t s)
 Multiplies the elements of row 'i' in matrix 'm' by scalar 's'. More...
 

Detailed Description

Basic mathematical operations for matrices (add, substract, etc.).

Function Documentation

◆ zsl_mtx_add()

int zsl_mtx_add ( struct zsl_mtx ma,
struct zsl_mtx mb,
struct zsl_mtx mc 
)

Adds matrices 'ma' and 'mb', assigning the output to 'mc'. Matrices 'ma', 'mb' and 'mc' must all be identically shaped.

Parameters
maPointer to the first input zsl_mtx.
mbPointer to the second input zsl_mtx.
mcPointer to the output zsl_mtx.
Returns
0 if everything executed correctly, or -EINVAL if the three matrices are not all identically shaped.

Definition at line 375 of file matrices.c.

Referenced by zsl_mtx_householder().

◆ zsl_mtx_add_d()

int zsl_mtx_add_d ( struct zsl_mtx ma,
struct zsl_mtx mb 
)

Adds matrices 'ma' and 'mb', assigning the output to 'ma'. Matrices 'ma', and 'mb' must be identically shaped.

Parameters
maPointer to the first input zsl_mtx. This matrix will be overwritten with the results of the addition operations!
mbPointer to the second input zsl_mtx.
Warning
This function is destructive to 'ma'!
Returns
0 if everything executed correctly, or -EINVAL if the two input matrices are not identically shaped.

Definition at line 381 of file matrices.c.

Referenced by zsl_mtx_eigenvectors().

◆ zsl_mtx_mult()

int zsl_mtx_mult ( struct zsl_mtx ma,
struct zsl_mtx mb,
struct zsl_mtx mc 
)

Multiplies matrix 'ma' by 'mb', assigning the output to 'mc'. Matrices 'ma' and 'mb' must be compatibly shaped, meaning that 'ma' must have the same numbers of columns as there are rows in 'mb'.

Parameters
maPointer to the first input zsl_mtx.
mbPointer to the second input zsl_mtx.
mcPointer to the output zsl_mtx.
Returns
0 if everything executed correctly, or -EINVAL if the input matrices are not compatibly shaped.

Definition at line 434 of file matrices.c.

Referenced by zsl_mtx_householder(), zsl_mtx_mult_d(), zsl_mtx_pinv(), zsl_mtx_qrd(), zsl_mtx_qrd_iter(), zsl_mtx_svd(), zsl_mtx_vec_wedge(), zsl_sta_mult_linear_reg(), zsl_sta_quad_fit(), and zsl_sta_weighted_mult_linear_reg().

◆ zsl_mtx_mult_d()

int zsl_mtx_mult_d ( struct zsl_mtx ma,
struct zsl_mtx mb 
)

Multiplies matrix 'ma' by 'mb', assigning the output to 'ma'. Matrices 'ma' and 'mb' must be compatibly shaped, meaning that 'ma' must have the same numbers of columns as there are rows in 'mb'. To use this function, 'mb' must be a square matrix. This function is destructive.

Parameters
maPointer to the first input zsl_mtx.
mbPointer to the second input zsl_mtx.
Returns
0 if everything executed correctly, or -EINVAL if the input matrices are not compatibly shaped.

Definition at line 468 of file matrices.c.

◆ zsl_mtx_scalar_mult_d()

int zsl_mtx_scalar_mult_d ( struct zsl_mtx m,
zsl_real_t  s 
)

Multiplies all elements in matrix 'm' by scalar value 's'.

Parameters
mPointer to the zsl_mtz to adjust.
sThe scalar value to multiply elements in matrix 'm' with.
Returns
0 if everything executed correctly, otherwise an appropriate error code.

Definition at line 488 of file matrices.c.

Referenced by zsl_mtx_eigenvectors(), zsl_mtx_householder(), zsl_mtx_inv_3x3(), and zsl_mtx_svd().

◆ zsl_mtx_scalar_mult_row_d()

int zsl_mtx_scalar_mult_row_d ( struct zsl_mtx m,
size_t  i,
zsl_real_t  s 
)

Multiplies the elements of row 'i' in matrix 'm' by scalar 's'.

Parameters
mPointer to the zsl_mtx to use.
iThe row number to multiply by scalar 's' (0-based).
sThe scalar to use when multiplying elements of row 'i'.
Returns
0 if everything executed correctly, or -EINVAL on an out of bounds error.

Definition at line 498 of file matrices.c.

Referenced by zsl_mtx_norm_elem(), and zsl_sta_weighted_mult_linear_reg().

◆ zsl_mtx_sub()

int zsl_mtx_sub ( struct zsl_mtx ma,
struct zsl_mtx mb,
struct zsl_mtx mc 
)

Subtracts matrices 'mb' from 'ma', assigning the output to 'mc'. Matrices 'ma', 'mb' and 'mc' must all be identically shaped.

Parameters
maPointer to the first input zsl_mtx.
mbPointer to the second input zsl_mtx.
mcPointer to the output zsl_mtx.
Returns
0 if everything executed correctly, or -EINVAL if the three matrices are not all identically shaped.

Definition at line 422 of file matrices.c.

Referenced by zsl_sta_mult_linear_reg(), and zsl_sta_weighted_mult_linear_reg().

◆ zsl_mtx_sub_d()

int zsl_mtx_sub_d ( struct zsl_mtx ma,
struct zsl_mtx mb 
)

Subtracts matrix 'mb' from 'ma', assigning the output to 'ma'. Matrices 'ma', and 'mb' must be identically shaped.

Parameters
maPointer to the first input zsl_mtx. This matrix will be overwritten with the results of the subtraction operations!
mbPointer to the second input zsl_mtx.
Warning
This function is destructive to 'ma'!
Returns
0 if everything executed correctly, or -EINVAL if the two input matrices are not identically shaped.

Definition at line 428 of file matrices.c.

◆ zsl_mtx_sum_rows_d()

int zsl_mtx_sum_rows_d ( struct zsl_mtx m,
size_t  i,
size_t  j 
)

Adds the values of row 'j' to row 'i' in matrix 'm'. This operation is destructive for row 'i'.

Parameters
mPointer to the zsl_mtx to use.
iThe first row number to add (0-based).
jThe second row number to add (0-based).
Returns
0 if everything executed correctly, or -EINVAL on an out of bounds error.

Definition at line 387 of file matrices.c.

Referenced by zsl_mtx_gauss_reduc().

◆ zsl_mtx_sum_rows_scaled_d()

int zsl_mtx_sum_rows_scaled_d ( struct zsl_mtx m,
size_t  i,
size_t  j,
zsl_real_t  s 
)

This function takes the coefficients of row 'j' and multiplies them by scalar 's', then adds the resulting coefficient to the parallel element in row 'i'. Row 'i' will be modified in this operation.

This function implements a key mechanism of Gauss–Jordan elimination, as can be seen in zsl_mtx_gauss_elim.

Parameters
mPointer to the zsl_mtx to use.
iThe row number to update (0-based).
jThe row number to scale and then add to 'i' (0-based).
sThe scalar value to apply to the values in row 'j'.
Returns
0 if everything executed correctly, otherwise an appropriate error code.

Definition at line 403 of file matrices.c.

Referenced by zsl_mtx_gauss_elim().