Zephyr Scientific Library (zscilib)
|
Basic mathematical operations (add, sum, norm, etc.). More...
Functions | |
int | zsl_vec_add (struct zsl_vec *v, struct zsl_vec *w, struct zsl_vec *x) |
Adds corresponding vector elements in 'v' and 'w', saving to 'x'. More... | |
int | zsl_vec_sub (struct zsl_vec *v, struct zsl_vec *w, struct zsl_vec *x) |
Subtracts corresponding vector elements in 'v' and 'w', saving to 'x'. More... | |
int | zsl_vec_neg (struct zsl_vec *v) |
Negates the elements in vector 'v'. More... | |
int | zsl_vec_sum (struct zsl_vec **v, size_t n, struct zsl_vec *w) |
Component-wise sum of a set of equal-length vectors. More... | |
int | zsl_vec_scalar_add (struct zsl_vec *v, zsl_real_t s) |
Adds a scalar to each element in a vector. More... | |
int | zsl_vec_scalar_mult (struct zsl_vec *v, zsl_real_t s) |
Multiply a vector by a scalar. More... | |
int | zsl_vec_scalar_div (struct zsl_vec *v, zsl_real_t s) |
Divide a vector by a scalar. More... | |
zsl_real_t | zsl_vec_dist (struct zsl_vec *v, struct zsl_vec *w) |
Calculates the distance between two vectors, which is equal to the norm of vector v - vector w. More... | |
int | zsl_vec_dot (struct zsl_vec *v, struct zsl_vec *w, zsl_real_t *d) |
Computes the dot (aka scalar) product of two equal-length vectors (the sum of their component-wise products). The dot product is an indicator of the "agreement" between two vectors, or can be used to determine how far vector w deviates from vector v. More... | |
zsl_real_t | zsl_vec_norm (struct zsl_vec *v) |
Calculates the norm or absolute value of vector 'v' (the square root of the vector's dot product). More... | |
int | zsl_vec_project (struct zsl_vec *u, struct zsl_vec *v, struct zsl_vec *w) |
Calculates the projection of vector 'u' over vector 'v', placing the results in vector 'w'. More... | |
int | zsl_vec_to_unit (struct zsl_vec *v) |
Converts (normalises) vector 'v' to a unit vector (a vector of magnitude or length 1). This is accomploished by dividing each element by the it's norm. More... | |
int | zsl_vec_cross (struct zsl_vec *v, struct zsl_vec *w, struct zsl_vec *c) |
Computes the cross (or vector) product of two 3-vectors. More... | |
zsl_real_t | zsl_vec_sum_of_sqrs (struct zsl_vec *v) |
Computes the vector's sum of squares. More... | |
int | zsl_vec_mean (struct zsl_vec **v, size_t n, struct zsl_vec *m) |
Computes the component-wise mean of a set of identically-sized vectors. More... | |
int | zsl_vec_ar_mean (struct zsl_vec *v, zsl_real_t *m) |
Computes the arithmetic mean of a vector. More... | |
int | zsl_vec_rev (struct zsl_vec *v) |
Reverses the order of the entries in vector 'v'. More... | |
int | zsl_vec_zte (struct zsl_vec *v) |
Rearranges the input vector to place any zero-values at the end. More... | |
Basic mathematical operations (add, sum, norm, etc.).
Adds corresponding vector elements in 'v' and 'w', saving to 'x'.
v | The first vector. |
w | The second vector. |
x | The output vector. |
Definition at line 71 of file vectors.c.
Referenced by zsl_mtx_gram_schmidt(), and zsl_mtx_householder().
int zsl_vec_ar_mean | ( | struct zsl_vec * | v, |
zsl_real_t * | m | ||
) |
Computes the arithmetic mean of a vector.
v | The vector to use. |
m | The arithmetic mean of vector v. |
Definition at line 334 of file vectors.c.
Referenced by zsl_sta_mean().
Computes the cross (or vector) product of two 3-vectors.
v | The first 3-vector. |
w | The second 3-vector. |
c | The cross product 3-vector output. |
Given two linearly independent 3-vectors (v and w), the cross product, (v X w), is a vector that is perpendicular to both v and w and thus 'normal' to the plane containing them.
If two vectors have the same direction (or have the exact opposite direction from one another, i.e. are not linearly independent) or if either one has zero length, then their cross product is zero.
The norm of the cross product equals the area of a parallelogram with vectors v and w for sides.
For a discusson of geometric and algebraic applications, see: https://en.wikipedia.org/wiki/Cross_product
zsl_real_t zsl_vec_dist | ( | struct zsl_vec * | v, |
struct zsl_vec * | w | ||
) |
int zsl_vec_dot | ( | struct zsl_vec * | v, |
struct zsl_vec * | w, | ||
zsl_real_t * | d | ||
) |
Computes the dot (aka scalar) product of two equal-length vectors (the sum of their component-wise products). The dot product is an indicator of the "agreement" between two vectors, or can be used to determine how far vector w deviates from vector v.
v | The first vector. |
w | The second vector. |
d | The dot product. |
Definition at line 199 of file vectors.c.
Referenced by zsl_vec_project(), and zsl_vec_sum_of_sqrs().
Computes the component-wise mean of a set of identically-sized vectors.
v | Pointer to the array of vectors. |
n | The number of vectors in 'v'. |
m | Pointer to the output vector whose i'th element is the mean of the i'th elements of the input vectors. |
int zsl_vec_neg | ( | struct zsl_vec * | v | ) |
Negates the elements in vector 'v'.
v | The vector to negate. |
Definition at line 104 of file vectors.c.
Referenced by zsl_mtx_eigenvectors().
zsl_real_t zsl_vec_norm | ( | struct zsl_vec * | v | ) |
Calculates the norm or absolute value of vector 'v' (the square root of the vector's dot product).
v | The vector to calculate the norm of. |
Definition at line 219 of file vectors.c.
Referenced by zsl_mtx_householder(), zsl_vec_dist(), and zsl_vec_to_unit().
Calculates the projection of vector 'u' over vector 'v', placing the results in vector 'w'.
u | Pointer to the first input vector. |
v | Pointer to the second input vector. |
w | Pointer to the output vector where the proj. results are stored. |
Definition at line 230 of file vectors.c.
Referenced by zsl_mtx_gram_schmidt().
int zsl_vec_rev | ( | struct zsl_vec * | v | ) |
int zsl_vec_scalar_add | ( | struct zsl_vec * | v, |
zsl_real_t | s | ||
) |
Adds a scalar to each element in a vector.
v | The vector to scale. |
s | The scalar to add to each element. |
Definition at line 144 of file vectors.c.
Referenced by zsl_sta_demean().
int zsl_vec_scalar_div | ( | struct zsl_vec * | v, |
zsl_real_t | s | ||
) |
Divide a vector by a scalar.
v | The vector to scale. |
s | The scalar to divide all elements by. |
Definition at line 166 of file vectors.c.
Referenced by zsl_mtx_householder().
int zsl_vec_scalar_mult | ( | struct zsl_vec * | v, |
zsl_real_t | s | ||
) |
Multiply a vector by a scalar.
v | The vector to scale. |
s | The scalar to multiply by. |
Definition at line 155 of file vectors.c.
Referenced by zsl_mtx_householder(), zsl_vec_mean(), zsl_vec_project(), and zsl_vec_to_unit().
Subtracts corresponding vector elements in 'v' and 'w', saving to 'x'.
v | The first vector. |
w | The second vector. |
x | The output vector. |
Definition at line 88 of file vectors.c.
Referenced by zsl_mtx_gram_schmidt(), and zsl_vec_dist().
Component-wise sum of a set of equal-length vectors.
v | Pointer to the array of vectors. |
n | The number of vectors in 'v'. |
w | Pointer to the output vector containing the component-wise sum. |
Definition at line 113 of file vectors.c.
Referenced by zsl_vec_mean().
zsl_real_t zsl_vec_sum_of_sqrs | ( | struct zsl_vec * | v | ) |
Computes the vector's sum of squares.
v | The vector to use. |
Definition at line 303 of file vectors.c.
Referenced by zsl_vec_norm().
int zsl_vec_to_unit | ( | struct zsl_vec * | v | ) |
Converts (normalises) vector 'v' to a unit vector (a vector of magnitude or length 1). This is accomploished by dividing each element by the it's norm.
v | The vector to convert to a unit vector. |
Definition at line 250 of file vectors.c.
Referenced by zsl_mtx_cols_norm().
int zsl_vec_zte | ( | struct zsl_vec * | v | ) |
Rearranges the input vector to place any zero-values at the end.
v | The input vector to rearrange. |
Definition at line 368 of file vectors.c.
Referenced by zsl_mtx_eigenvalues().