JWS C Library
C language utility library
vector_math.h File Reference

Declarations for mathematical vector operations. More...

#include <jwsc/config.h>
#include <stdlib.h>
#include "jwsc/base/error.h"
#include "jwsc/math/complex.h"
#include "jwsc/vector/vector.h"
Include dependency graph for vector_math.h:

Go to the source code of this file.

Functions

add_scalar_to_vector

Adds a scalar to a vector.

void add_scalar_to_vector_f (Vector_f **v_out, const Vector_f *v_in, float a)
 Adds a scalar to a single precision vector.
void add_scalar_to_vector_d (Vector_d **v_out, const Vector_d *v_in, double a)
 Adds a scalar to a double precision vector.
void add_scalar_to_vector_cf (Vector_cf **v_out, const Vector_cf *v_in, Complex_f z)
 Adds a scalar to a single precision complex vector.
void add_scalar_to_vector_cd (Vector_cd **v_out, const Vector_cd *v_in, Complex_d z)
 Adds a scalar to a double precision complex vector.
multiply_vector_by_scalar

Multiplies a vector by a scalar.

void multiply_vector_by_scalar_f (Vector_f **v_out, const Vector_f *v_in, float a)
 Multiplies a single precision vector by a scalar.
void multiply_vector_by_scalar_d (Vector_d **v_out, const Vector_d *v_in, double a)
 Multiplies a double precision vector by a scalar.
void multiply_vector_by_scalar_cf (Vector_cf **v_out, const Vector_cf *v_in, Complex_f z)
 Multiplies a single precision complex vector by a scalar.
void multiply_vector_by_scalar_cd (Vector_cd **v_out, const Vector_cd *v_in, Complex_d z)
 Multiplies a double precision complex vector by a scalar.
calc_vector_dot_prod

Calculates the dot product of two real vectors.

Errorcalc_vector_dot_prod_f (float *dp_out, const Vector_f *v_1, const Vector_f *v_2)
 Calculates the dot product of two single precision vectors.
Errorcalc_vector_dot_prod_d (double *dp_out, const Vector_d *v_1, const Vector_d *v_2)
 Calculates the dot product of two double precision vectors.
calc_3d_vector_cross_prod

Calculates the cross product of two R^3 vectors.

Errorcalc_3d_vector_cross_prod_f (Vector_f **v_out, const Vector_f *v_1, const Vector_f *v_2)
 Calculates the cross product of two single precision R^3 vectors.
Errorcalc_3d_vector_cross_prod_d (Vector_d **v_out, const Vector_d *v_1, const Vector_d *v_2)
 Calculates the cross product of two double precision R^3 vectors.
calc_vector_asum

Calculates the absolute sum of a real vector.

void calc_vector_asum_f (float *sum_out, const Vector_f *v)
 Calculates the absolute value sum of a single precision vector.
void calc_vector_asum_d (double *sum_out, const Vector_d *v)
 Calculates the absolute value sum of a double precision vector.
calc_vector_mag

Calculates the magnitude of a real vector.

void calc_vector_mag_f (float *mag_out, const Vector_f *v)
 Calculates the magnitude of a single precision vector.
void calc_vector_mag_d (double *mag_out, const Vector_d *v)
 Calculates the magnitude of a double precision vector.
normalize_vector_sum

Normalizes a real vector by its sum.

void normalize_vector_sum_f (Vector_f **v_out, const Vector_f *v_in)
 Normalizes a single precision vector by its sum.
void normalize_vector_sum_d (Vector_d **v_out, const Vector_d *v_in)
 Normalizes a double precision vector by its sum.
normalize_vector_mag

Normalizes a real vector by its magnitude.

void normalize_vector_mag_f (Vector_f **v_out, const Vector_f *v_in)
 Normalizes a single precision vector by its magnitude.
void normalize_vector_mag_d (Vector_d **v_out, const Vector_d *v_in)
 Normalizes a double precision vector by its magnitude.
add_vectors

Adds two vectors element-wise.

Erroradd_vectors_f (Vector_f **v_out, const Vector_f *v_1, const Vector_f *v_2)
 Adds two single precision vectors element-wise.
Erroradd_vectors_d (Vector_d **v_out, const Vector_d *v_1, const Vector_d *v_2)
 Adds two double precision vectors element-wise.
Erroradd_vectors_cf (Vector_cf **v_out, const Vector_cf *v_1, const Vector_cf *v_2)
 Adds two single precision complex vectors element-wise.
Erroradd_vectors_cd (Vector_cd **v_out, const Vector_cd *v_1, const Vector_cd *v_2)
 Adds two double precision complex vectors element-wise.
subtract_vectors

Subtracts two vectors element-wise.

Errorsubtract_vectors_f (Vector_f **v_out, const Vector_f *v_1, const Vector_f *v_2)
 Subtracts two single precision vectors element-wise.
Errorsubtract_vectors_d (Vector_d **v_out, const Vector_d *v_1, const Vector_d *v_2)
 Subtracts two double precision vectors element-wise.
Errorsubtract_vectors_cf (Vector_cf **v_out, const Vector_cf *v_1, const Vector_cf *v_2)
 Subtracts two single precision complex vectors element-wise.
Errorsubtract_vectors_cd (Vector_cd **v_out, const Vector_cd *v_1, const Vector_cd *v_2)
 Subtracts two double precision complex vectors element-wise.

Detailed Description

Declarations for mathematical vector operations.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

Definition in file vector_math.h.


Function Documentation

void add_scalar_to_vector_f ( Vector_f **  v_out,
const Vector_f v_in,
float  a 
)

Adds a scalar to a single precision vector.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to add scalar to.
aScalar to add to the values of v_in.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 78 of file vector_math.c.

void add_scalar_to_vector_d ( Vector_d **  v_out,
const Vector_d v_in,
double  a 
)

Adds a scalar to a double precision vector.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to add scalar to.
aScalar to add to the values of v_in.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 106 of file vector_math.c.

void add_scalar_to_vector_cf ( Vector_cf **  v_out,
const Vector_cf v_in,
Complex_f  z 
)

Adds a scalar to a single precision complex vector.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to add scalar to.
zScalar to add to the values of v_in.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 135 of file vector_math.c.

void add_scalar_to_vector_cd ( Vector_cd **  v_out,
const Vector_cd v_in,
Complex_d  z 
)

Adds a scalar to a double precision complex vector.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to add scalar to.
zScalar to add to the values of v_in.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 169 of file vector_math.c.

void multiply_vector_by_scalar_f ( Vector_f **  v_out,
const Vector_f v_in,
float  a 
)

Multiplies a single precision vector by a scalar.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to multiply scalar by.
aScalar to multiply the values of v_in by.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 215 of file vector_math.c.

void multiply_vector_by_scalar_d ( Vector_d **  v_out,
const Vector_d v_in,
double  a 
)

Multiplies a double precision vector by a scalar.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to multiply scalar by.
aScalar to multiply the values of v_in by.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 263 of file vector_math.c.

void multiply_vector_by_scalar_cf ( Vector_cf **  v_out,
const Vector_cf v_in,
Complex_f  z 
)

Multiplies a single precision complex vector by a scalar.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to multiply scalar by.
zScalar to multiply the values of v_in by.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 311 of file vector_math.c.

void multiply_vector_by_scalar_cd ( Vector_cd **  v_out,
const Vector_cd v_in,
Complex_d  z 
)

Multiplies a double precision complex vector by a scalar.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to multiply scalar by.
zScalar to multiply the values of v_in by.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 364 of file vector_math.c.

Error* calc_vector_dot_prod_f ( float *  dp_out,
const Vector_f v_1,
const Vector_f v_2 
)

Calculates the dot product of two single precision vectors.

The vectors must have equal dimensions.

Parameters:
dp_outResult parameter.
v_1Dot product vector.
v_2Dot product vector.
Returns:
On success, NULL is returned; otherwise an Error is returned.

Definition at line 432 of file vector_math.c.

Error* calc_vector_dot_prod_d ( double *  dp_out,
const Vector_d v_1,
const Vector_d v_2 
)

Calculates the dot product of two double precision vectors.

The vectors must have equal dimensions.

Parameters:
dp_outResult parameter.
v_1Dot product vector.
v_2Dot product vector.
Returns:
On success, NULL is returned; otherwise an Error is returned.

Definition at line 475 of file vector_math.c.

Error* calc_3d_vector_cross_prod_f ( Vector_f **  v_out,
const Vector_f v_1,
const Vector_f v_2 
)

Calculates the cross product of two single precision R^3 vectors.

The Vector must have 3 dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1First vector in the cross product operation.
v_2Second vector in the cross product operation.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 534 of file vector_math.c.

Error* calc_3d_vector_cross_prod_d ( Vector_d **  v_out,
const Vector_d v_1,
const Vector_d v_2 
)

Calculates the cross product of two double precision R^3 vectors.

The Vector must have 3 dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1First vector in the cross product operation.
v_2Second vector in the cross product operation.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 582 of file vector_math.c.

void calc_vector_asum_f ( float *  sum_out,
const Vector_f v 
)

Calculates the absolute value sum of a single precision vector.

Parameters:
sum_outResult parameter. Sum of the absolute values of v.
vVector to calculate the sum of.

Definition at line 630 of file vector_math.c.

void calc_vector_asum_d ( double *  sum_out,
const Vector_d v 
)

Calculates the absolute value sum of a double precision vector.

Parameters:
sum_outResult parameter. Sum of the absolute values of v.
vVector to calculate the sum of.

Definition at line 652 of file vector_math.c.

void calc_vector_mag_f ( float *  mag_out,
const Vector_f v 
)

Calculates the magnitude of a single precision vector.

Parameters:
mag_outResult parameter. Magnitude of v.
vVector to calculate the magnitude of.

Definition at line 686 of file vector_math.c.

void calc_vector_mag_d ( double *  mag_out,
const Vector_d v 
)

Calculates the magnitude of a double precision vector.

Parameters:
mag_outResult parameter. Magnitude of v.
vVector to calculate the magnitude of.

Definition at line 710 of file vector_math.c.

void normalize_vector_sum_f ( Vector_f **  v_out,
const Vector_f v_in 
)

Normalizes a single precision vector by its sum.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to normalize.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 749 of file vector_math.c.

void normalize_vector_sum_d ( Vector_d **  v_out,
const Vector_d v_in 
)

Normalizes a double precision vector by its sum.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to normalize.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 772 of file vector_math.c.

void normalize_vector_mag_f ( Vector_f **  v_out,
const Vector_f v_in 
)

Normalizes a single precision vector by its magnitude.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to normalize.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 807 of file vector_math.c.

void normalize_vector_mag_d ( Vector_d **  v_out,
const Vector_d v_in 
)

Normalizes a double precision vector by its magnitude.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_inVector to normalize.
Note:
If *v_out == v_in, then v_in is overwritten.

Definition at line 830 of file vector_math.c.

Error* add_vectors_f ( Vector_f **  v_out,
const Vector_f v_1,
const Vector_f v_2 
)

Adds two single precision vectors element-wise.

The Vector must have equal dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1Vector to add.
v_2Vector to add.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 874 of file vector_math.c.

Error* add_vectors_d ( Vector_d **  v_out,
const Vector_d v_1,
const Vector_d v_2 
)

Adds two double precision vectors element-wise.

The Vector must have equal dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1Vector to add.
v_2Vector to add.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 955 of file vector_math.c.

Error* add_vectors_cf ( Vector_cf **  v_out,
const Vector_cf v_1,
const Vector_cf v_2 
)

Adds two single precision complex vectors element-wise.

The Vector must have equal dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1Vector to add.
v_2Vector to add.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 1036 of file vector_math.c.

Error* add_vectors_cd ( Vector_cd **  v_out,
const Vector_cd v_1,
const Vector_cd v_2 
)

Adds two double precision complex vectors element-wise.

The Vector must have equal dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1Vector to add.
v_2Vector to add.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 1121 of file vector_math.c.

Error* subtract_vectors_f ( Vector_f **  v_out,
const Vector_f v_1,
const Vector_f v_2 
)

Subtracts two single precision vectors element-wise.

The Vector must have equal dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1Vector to subtract.
v_2Vector to subtract.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 1218 of file vector_math.c.

Error* subtract_vectors_d ( Vector_d **  v_out,
const Vector_d v_1,
const Vector_d v_2 
)

Subtracts two double precision vectors element-wise.

The Vector must have equal dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1Vector to subtract.
v_2Vector to subtract.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 1303 of file vector_math.c.

Error* subtract_vectors_cf ( Vector_cf **  v_out,
const Vector_cf v_1,
const Vector_cf v_2 
)

Subtracts two single precision complex vectors element-wise.

The Vector must have equal dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1Vector to subtract.
v_2Vector to subtract.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 1388 of file vector_math.c.

Error* subtract_vectors_cd ( Vector_cd **  v_out,
const Vector_cd v_1,
const Vector_cd v_2 
)

Subtracts two double precision complex vectors element-wise.

The Vector must have equal dimensions.

Parameters:
v_outResult parameter. If *v_out is NULL, a vector is allocated; otherwise its space is re-used.
v_1Vector to subtract.
v_2Vector to subtract.
Returns:
On success, NULL is returned. On error, an Error is returned and *v_out is freed and set to NULL (if it is not v_1 or v_2).
Note:
If *v_out == v_[12], it is overwritten.

Definition at line 1477 of file vector_math.c.