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

Vector computations. More...

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

Go to the source code of this file.

Macros

#define vector_t   double
 Define the data type of the vector elements.
 

Functions

void vector_clear (uint8_t size, vector_t arr[])
 Clear all the elements of the vector. More...
 
void vector_copy (uint8_t size, vector_t src_arr[], vector_t dest_arr[])
 Copy the elements of the source vector to the destination vector. More...
 
vector_t vector_get_norm2 (uint8_t length, vector_t arr[])
 Compute the 2-norm norm of a vector. More...
 
vector_t vector_get_square_norm2 (uint8_t length, vector_t arr[])
 Compute the squared 2-norm norm of a vector . More...
 
vector_t vector_get_sum (uint8_t length, vector_t arr[])
 Compute the sum of the elements of a vector. More...
 
vector_t vector_get_mean_value (uint8_t length, vector_t arr[])
 Compute the average or mean value of a vector. More...
 
void vector_sub (uint8_t size, vector_t a_vec[], vector_t b_vec[], vector_t a_minus_b[])
 Compute the subtraction of two vectors. More...
 
void vector_add (uint8_t size, vector_t a_vec[size], vector_t b_vec[size], vector_t a_plus_b_vec[size])
 Compute the addition of two vectors. More...
 
void vector_mul (uint8_t size, vector_t a_vec[size], vector_t b_vec[size], vector_t a_mul_b_vec[size])
 Compute the multiplication of two vectors. More...
 
void vector_square (uint8_t n, vector_t vec[n], vector_t square_vec[n])
 Compute the square of a vector. More...
 
void vector_in_place_scalar_mul (uint8_t size, vector_t a_vec[size], vector_t scl)
 Compute the product of a vector with a real number. More...
 
void vector_scalar_mul (uint8_t size, vector_t src_vec[size], vector_t scl, vector_t dest_vec[])
 Compute the product of a vector with a real number. More...
 
void vector_scalar_div (uint8_t size, vector_t a_vec[size], vector_t scl)
 Compute the division of a vector with a real number. More...
 
vector_t vector_get_euclidean_distance (uint8_t length, vector_t vec1[], vector_t vec2[])
 Compute the Euclidean distance between two vectors. More...
 
vector_t vector_get_scalar_product (uint8_t n, vector_t vec1[n], vector_t vec2[n])
 Compute the dot product of two vectors. More...
 
bool vector_is_equal (uint16_t length, vector_t vec_1[], vector_t vec_2[])
 Determine the equality of two vectors. More...
 
bool vector_uint32_is_equal (uint32_t length, uint32_t vec_1[], uint32_t vec_2[])
 Determine the equality of two vectors of type uint32_t. More...
 
void vector_get_index_vector (uint8_t k, uint8_t n, vector_t unsorted_vector[n], vector_t sorted_vector[n], uint8_t index_vector[n])
 Determine the index of the vector elements before sorting. More...
 
vector_t vector_get_max_and_index (uint8_t length, vector_t vec[], uint8_t *index)
 Compute the maximal value and its index of a vector. More...
 
vector_t vector_get_residual (uint8_t length, vector_t a_vec[], vector_t b_vec[])
 Compute the residual of two vectors. More...
 
void vector_get_elements (vector_t src_vec[], uint8_t k, uint8_t index_vec[], vector_t dst_vec[])
 Get the elements of the vector by an index vector. More...
 
void vector_print (uint32_t length, vector_t arr[])
 Display the values of the vector's elements. More...
 
void vector_print_u8_array (uint32_t length, uint8_t arr[])
 Display the values of the vector's elements of type uint8_t. More...
 
void vector_flex_print (uint32_t length, vector_t arr[], uint8_t before_dot, uint8_t after_dot)
 Display the values of the vector's elements. More...
 

Detailed Description

Vector computations.

Vector computations include operations such as addition, subtraction, and inner product (dot product).

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

Definition in file vector.h.

Function Documentation

◆ vector_add()

void vector_add ( uint8_t  size,
vector_t  a_vec[size],
vector_t  b_vec[size],
vector_t  a_plus_b_vec[size] 
)

Compute the addition of two vectors.

Add b_vec to a_vec and return the result in a_plus_b.

Parameters
[in]sizenumber of elements to subtract.
[in]a_vec[]pointer to the first vector.
[in]b_vec[]pointer to the second vector.
[out]a_plus_b_vec[]pointer to the destination vector.

Definition at line 104 of file vector.c.

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

◆ vector_clear()

void vector_clear ( uint8_t  size,
vector_t  arr[] 
)

Clear all the elements of the vector.

Parameters
[in]sizesize of the vector.
[in]arr[]pointer to the vector.

Definition at line 32 of file vector.c.

References vector_t.

Referenced by dist_based_jacobian_get_JTf(), fsolve_test(), optimization_exponential_data_test(), optimization_sinusoidal_data_test(), optimization_test(), position_optimization_test(), and vector_test().

◆ vector_copy()

void vector_copy ( uint8_t  size,
vector_t  src_arr[],
vector_t  dest_arr[] 
)

Copy the elements of the source vector to the destination vector.

Parameters
[in]sizenumber of elements to copy.
[in]src_arr[]pointer to the source vector.
[in]dest_arr[]pointer to the destination vector.

Definition at line 37 of file vector.c.

References vector_t.

Referenced by damped_newton_raphson(), loc_gauss_newton(), loc_levenberg_marquardt(), modified_gauss_newton(), multipath_algo_own_norm_distr_test(), newton_raphson(), opt_levenberg_marquardt(), recog_mitigate_multipath(), and vector_test().

◆ vector_flex_print()

void vector_flex_print ( uint32_t  length,
vector_t  arr[],
uint8_t  before_dot,
uint8_t  after_dot 
)

Display the values of the vector's elements.

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

Parameters
[in]lengthsize of the vector to display.
[in]arrpointer to the vector.
[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 284 of file vector.c.

References utils_printf().

Referenced by distance_based_test(), fsolve_test(), magnetic_based_get_magnetic_field(), magnetic_based_test(), multipath_algo_own_norm_distr_test(), optimization_test(), position_optimization_test(), solve_big_matrix_test(), solve_test(), utils_test(), and vector_test().

◆ vector_get_elements()

void vector_get_elements ( vector_t  src_vec[],
uint8_t  k,
uint8_t  index_vec[],
vector_t  dst_vec[] 
)

Get the elements of the vector by an index vector.

Parameters
[in]src_vec[]pointer to source vector.
[in]ksize of the index vector.
[in]index_vec[]pointer to the index vector.
[out]dst_vec[]pointer to the destination vector

Definition at line 235 of file vector.c.

Referenced by multipath_algo_own_norm_distr_test().

◆ vector_get_euclidean_distance()

vector_t vector_get_euclidean_distance ( uint8_t  length,
vector_t  vec1[],
vector_t  vec2[] 
)

Compute the Euclidean distance between two vectors.

Parameters
[in]lengthsize of the vector.
[in]vec1[]pointer to the first vector.
[in]vec2[]pointer to the second vector.
Returns
the Euclidean distance.

Definition at line 163 of file vector.c.

References vector_get_norm2(), vector_sub(), and vector_t.

Referenced by loc_gauss_newton(), modified_gauss_newton(), newton_raphson(), and vector_test().

◆ vector_get_index_vector()

void vector_get_index_vector ( uint8_t  k,
uint8_t  n,
vector_t  unsorted_vector[n],
vector_t  sorted_vector[n],
uint8_t  index_vector[n] 
)

Determine the index of the vector elements before sorting.

Determine the index of the elements of a sorted vector. These indices correspond to the positions of the elements in the unsorted vector.

Parameters
[in]ksize of the unsorted vector.
[in]nsize of the sorted vector.
[in]unsorted_vector[]pointer to the unsorted vector.
[in]sorted_vector[]pointer to the sorted vector.
[out]index_vector[]pointer to the index vector.

Definition at line 214 of file vector.c.

Referenced by recog_mitigate_multipath().

◆ vector_get_max_and_index()

vector_t vector_get_max_and_index ( uint8_t  length,
vector_t  vec[],
uint8_t *  index 
)

Compute the maximal value and its index of a vector.

Parameters
[in]lengthvector size.
[in]vec[]pointer to the vector.
[in]indexpointer to the index.
Returns
the maximal value of the vector.

Definition at line 175 of file vector.c.

References vector_t.

◆ vector_get_mean_value()

vector_t vector_get_mean_value ( uint8_t  length,
vector_t  arr[] 
)

Compute the average or mean value of a vector.

Parameters
[in]lengthsize of the vector.
[in]arr[]pointer to the vector.
Returns
the mean value of the vector.

Definition at line 78 of file vector.c.

References vector_t.

Referenced by vector_test().

◆ vector_get_norm2()

vector_t vector_get_norm2 ( uint8_t  length,
vector_t  arr[] 
)

Compute the 2-norm norm of a vector.

Parameters
[in]lengthsize of the vector.
[in]arr[]pointer to the vector.
Returns
the 2-norm of the vector.

Definition at line 42 of file vector.c.

References vector_t.

Referenced by damped_newton_raphson(), dist_based_get_distance_to_anchor(), get_damped_norm(), loc_gauss_newton(), loc_levenberg_marquardt(), magnetic_based_get_distances_to_anchors(), modified_gauss_newton(), opt_levenberg_marquardt(), recog_mitigate_multipath(), vector_get_euclidean_distance(), vector_get_residual(), and vector_test().

◆ vector_get_residual()

vector_t vector_get_residual ( uint8_t  length,
vector_t  a_vec[],
vector_t  b_vec[] 
)

Compute the residual of two vectors.

Parameters
[in]lengthvector size.
[in]a_vec[]pointer to the first vector.
[in]b_vec[]pointer to the second vector.
Returns
the residual of the two vectors.

Definition at line 227 of file vector.c.

References vector_get_norm2(), vector_sub(), and vector_t.

◆ vector_get_scalar_product()

vector_t vector_get_scalar_product ( uint8_t  n,
vector_t  vec1[n],
vector_t  vec2[n] 
)

Compute the dot product of two vectors.

Parameters
[in]nsize of the vectors.
[in]vec1[]pointer to the first vector.
[in]vec2[]pointer to the second vector.
Returns
the scalar product of two vectors.

Definition at line 190 of file vector.c.

References vector_t.

Referenced by loc_levenberg_marquardt_correction(), opt_levenberg_marquardt_correction(), and vector_test().

◆ vector_get_square_norm2()

vector_t vector_get_square_norm2 ( uint8_t  length,
vector_t  arr[] 
)

Compute the squared 2-norm norm of a vector .

Parameters
[in]lengthsize of the vector.
[in]arr[]pointer to the vector.
Returns
the squared 2-norm of the vector.

Definition at line 54 of file vector.c.

References vector_t.

Referenced by vector_test().

◆ vector_get_sum()

vector_t vector_get_sum ( uint8_t  length,
vector_t  arr[] 
)

Compute the sum of the elements of a vector.

Parameters
[in]lengthsize of the vector.
[in]arr[]pointer to the vector.
Returns
the sum of the elements of the vector.

Definition at line 66 of file vector.c.

References vector_t.

Referenced by vector_test().

◆ vector_in_place_scalar_mul()

void vector_in_place_scalar_mul ( uint8_t  size,
vector_t  a_vec[size],
vector_t  scl 
)

Compute the product of a vector with a real number.

Multiple the elements of a vector with a scalar and return the result in the vector itself.

Parameters
[in]sizenumber of elements to multiply with a scalar.
[in,out]a_vec[]pointer to the source/destination vector.
[in]scla scalar.

Definition at line 131 of file vector.c.

Referenced by get_delta_x().

◆ vector_is_equal()

bool vector_is_equal ( uint16_t  length,
vector_t  vec_1[],
vector_t  vec_2[] 
)

Determine the equality of two vectors.

Parameters
[in]lengthsize of the vector.
[in]vec_1[]pointer to the first vector.
[in]vec_2[]pointer to the second vector.
Returns
true, if the two vectors are equal.
false, if not.

Definition at line 202 of file vector.c.

Referenced by vector_test().

◆ vector_mul()

void vector_mul ( uint8_t  size,
vector_t  a_vec[size],
vector_t  b_vec[size],
vector_t  a_mul_b_vec[size] 
)

Compute the multiplication of two vectors.

Multiple vectors a_vec and b_vec element by element and return the result in a_mul_b.

Parameters
[in]sizenumber of elements to multiply.
[in]a_vec[]pointer to the first vector.
[in]b_vec[]pointer to the second vector.
[out]a_mul_b_vec[]pointer to the destination vector.

Definition at line 114 of file vector.c.

Referenced by vector_test().

◆ vector_print()

void vector_print ( uint32_t  length,
vector_t  arr[] 
)

Display the values of the vector's elements.

Parameters
[in]lengthsize of the vector to display.
[in]arrpointer to the vector.

Definition at line 255 of file vector.c.

◆ vector_print_u8_array()

void vector_print_u8_array ( uint32_t  length,
uint8_t  arr[] 
)

Display the values of the vector's elements of type uint8_t.

Parameters
[in]lengthsize of the vector to display.
[in]arrpointer to the vector.

Definition at line 269 of file vector.c.

◆ vector_scalar_div()

void vector_scalar_div ( uint8_t  size,
vector_t  a_vec[size],
vector_t  scl 
)

Compute the division of a vector with a real number.

Divide the elements of a vector with a scalar and return the result in the vector itself.

Parameters
[in]sizenumber of elements to divide with a scalar.
[in,out]a_vec[]pointer to the source/destination vector.
[in]scla scalar.

Definition at line 151 of file vector.c.

◆ vector_scalar_mul()

void vector_scalar_mul ( uint8_t  size,
vector_t  src_vec[size],
vector_t  scl,
vector_t  dest_vec[] 
)

Compute the product of a vector with a real number.

Multiple the elements of a vector with a scalar and return the result in other vector.

Parameters
[in]sizenumber of elements to multiply with a scalar.
[in]src_vec[]pointer to the source vector.
[in]scla scalar.
[out]dest_vecpointer to the destination vector.

Definition at line 141 of file vector.c.

Referenced by damped_newton_raphson().

◆ vector_square()

void vector_square ( uint8_t  n,
vector_t  vec[n],
vector_t  square_vec[n] 
)

Compute the square of a vector.

Square the elements of vector vec and return the result in square_vec.

Parameters
[in]nnumber of elements to square.
[in]vec[]pointer to the source vector.
[out]square_vec[]pointer to the destination vector.

Definition at line 124 of file vector.c.

Referenced by recog_mitigate_multipath().

◆ vector_sub()

void vector_sub ( uint8_t  size,
vector_t  a_vec[],
vector_t  b_vec[],
vector_t  a_minus_b[] 
)

Compute the subtraction of two vectors.

Substact b_vec from a_vec and return the result in a_minus_b.

Parameters
[in]sizenumber of elements to subtract.
[in]a_vec[]pointer to the first vector.
[in]b_vec[]pointer to the second vector.
[out]a_minus_b[]pointer to the destination vector.

Definition at line 94 of file vector.c.

Referenced by dist_based_get_distance_to_anchor(), loc_gauss_newton(), magnetic_based_get_distances_to_anchors(), modified_gauss_newton(), newton_raphson(), recog_mitigate_multipath(), vector_get_euclidean_distance(), vector_get_residual(), and vector_test().

◆ vector_uint32_is_equal()

bool vector_uint32_is_equal ( uint32_t  length,
uint32_t  vec_1[],
uint32_t  vec_2[] 
)

Determine the equality of two vectors of type uint32_t.

Parameters
[in]lengthsize of the vector.
[in]vec_1[]pointer to the first vector.
[in]vec_2[]pointer to the second vector.
Returns
true, if the two vectors are equal.
false, if not.

Definition at line 243 of file vector.c.