vector module¶
Vector algebra/calculus methods for numpy ndarrays.
Module author: Michael S. Chapman <chapmanms@missouri.edu>
- Authors:
Michael S. Chapman <chapmanms@missouri.edu>
Oregon Health & Science University & University of Missouri
- Version:
1, Nov 26, 2024
Changed in version 0.5.6: (04/02/18) Initial coding
Changed in version 1.0.0: 11/17/20 Python 2.7 –> 3.6
- vector.assertOneD(a)¶
- vector.assertSameSize(a, b)¶
- vector.crossDeriv(a, b)¶
Derivative of the vector product v = a x b with respect to components of a & b
- Parameters:
b (ndarray a,) – one-dimensional, same length
- Returns:
partial derivatives for the vector product v, for each component of a, b
- Return type:
(ndarray, shape=(a.shape, a.shape),)*2
For:
, where:
;
and
are the basis vectors:
(1)¶
(2)¶
(3)¶
(4)¶
(5)¶
(6)¶
(7)¶
(8)¶
(9)¶
Returns
, where:
(10)¶
and where:
(11)¶
- vector.crossNorm(a, b)¶
Length of the vector product v = a x b.
- Parameters:
b (ndarray a,) – one-dimensional, same length
- Returns:
norm-2 length of the vector product v
- Return type:
float
- vector.crossNormDeriv(a, b)¶
Derivative of the length of the vector product a x b with respect to components of a & b
- Parameters:
b (ndarray a,) – one-dimensional, same length
- Returns:
partial derivatives for the vector product v, for each component of a, b
- Return type:
(ndarray, shape=(a.shape, a.shape),)*2
For:
,
(12)¶
(By the chain rule, where the 1st term comes from normDeriv() and the 2nd from crossDeriv().)
- vector.crossUnit(a, b)¶
Unit vector in direction of vector product, v = a x b.
- Parameters:
b (ndarray a,) – one-dimensional, same length
- Returns:
unit vector along vector product v
- Return type:
ndarray, shape=a.size
- vector.crossUnitDeriv(a, b)¶
Derivative of the unit vector normal to a & b with respect to components of a & b
- Parameters:
b (ndarray a,) – one-dimensional, same length
- Returns:
partial derivatives for the vector product v, for each component of a, b
- Return type:
(ndarray, shape=(a.shape, a.shape),)*2
For:
,
(13)¶
(By the chain rule, where the 1st term comes from normDeriv() and the 2nd from crossDeriv().)
- vector.dotDeriv(a, b)¶
Derivative of the scalar product with respect to a, b.
Note that the return is the trivial (b, a) if want to hard-wire.
- Parameters:
b (ndarray a,) – one-dimensional, same length
- Returns:
scalar product derivatives for each component of a, b
- Return type:
(ndarray, ndarray), shaped like a=b
For:
,
(14)¶
Similarly,
(15)¶
- vector.normDeriv(a)¶
Derivative of the 2-norm length of a vector with respect to its components.
- Parameters:
a (ndarray) – one-dimensional
- Returns:
derivative with respect to each component
- Return type:
ndarray, shaped like a