Jump to navigation

Namespace: vectormath

Numbas.vectormath

Vector operations.

These operations are very lax about the dimensions of vectors - they stick zeros in when pairs of vectors don't line up exactly

Source:

Methods

(static) abs(a) → {Number}

Length of a vector

Parameters:
Name Type Description
a vector
Returns:
Type Description
Number
Source:

(static) abs_squared(a) → {Number}

Length of a vector, squared

Parameters:
Name Type Description
a vector
Returns:
Type Description
Number
Source:

(static) add(a, b) → {vector}

Add two vectors

Parameters:
Name Type Description
a vector
b vector
Returns:
Type Description
vector
Source:

(static) angle(a, b) → {Number}

Angle between vectors a and b, in radians, or 0 if either vector has length 0.

Parameters:
Name Type Description
a vector
b vector
Returns:
Type Description
Number
Source:

(static) cross(a, b) → {vector}

Vector cross product - each argument can be a vector, or a matrix with one row, which is converted to a vector.

Parameters:
Name Type Description
a vector | matrix
b vector | matrix
Throws:
  • "vectormaths.cross.matrix too big" if either of a or b is bigger than 1xN or Nx1.

    Type
    Numbas.Error
  • "vectormath.cross.not 3d" if either of the vectors is not 3D.

    Type
    Numbas.Error
Returns:
Type Description
vector
Source:

(static) div(v, k) → {vector}

Divide by a scalar

Parameters:
Name Type Description
v vector
k Number
Returns:
Type Description
vector
Source:

(static) dot(a, b) → {Number}

Vector dot product - each argument can be a vector, or a matrix with one row or one column, which is converted to a vector.

Parameters:
Name Type Description
a vector | matrix
b vector | matrix
Throws:

"vectormaths.dot.matrix too big" if either of a or b is bigger than 1xN or Nx1.

Type
Numbas.Error
Returns:
Type Description
Number
Source:

(static) eq(a, b) → {Boolean}

Are two vectors equal? True if each pair of corresponding components is equal.

Parameters:
Name Type Description
a vector
b vector
Returns:
Type Description
Boolean
Source:

(static) is_zero(v) → {Boolean}

Is every component of this vector zero?

Parameters:
Name Type Description
v vector
Returns:
Type Description
Boolean
Source:

(static) map(v, fn) → {vector}

Apply given function to each element

Parameters:
Name Type Description
v vector
fn function
Returns:
Type Description
vector
Source:

(static) matrixmul(m, v) → {vector}

Multiply a vector on the left by a matrix

Parameters:
Name Type Description
m matrix
v vector
Returns:
Type Description
vector
Source:

(static) mul(k, v) → {vector}

Multiply by a scalar

Parameters:
Name Type Description
k Number
v vector
Returns:
Type Description
vector
Source:

(static) negate(v) → {vector}

Negate a vector - negate each of its components

Parameters:
Name Type Description
v vector
Returns:
Type Description
vector
Source:

(static) neq(a, b) → {Boolean}

Are two vectors unequal?

Parameters:
Name Type Description
a vector
b vector
Returns:
Type Description
Boolean
Source:
See:

(static) precround(v, dp) → {vector}

Round each element to given number of decimal places

Parameters:
Name Type Description
v vector
dp Number

number of decimal places

Returns:
Type Description
vector
Source:

(static) siground(v, sf) → {vector}

Round each element to given number of significant figures

Parameters:
Name Type Description
v vector
sf Number

number of decimal places

Returns:
Type Description
vector
Source:

(static) sub(a, b) → {vector}

Subtract one vector from another

Parameters:
Name Type Description
a vector
b vector
Returns:
Type Description
vector
Source:

(static) toMatrix(v) → {matrix}

Convert a vector to a 1-column matrix

Parameters:
Name Type Description
v vector
Returns:
Type Description
matrix
Source:

(static) transpose(v) → {matrix}

Transpose of a vector

Parameters:
Name Type Description
v vector
Returns:
Type Description
matrix
Source:

(static) vectormatrixmul(v, m) → {vector}

Multiply a vector on the right by a matrix. The vector is considered as a column vector.

Parameters:
Name Type Description
v vector
m matrix
Returns:
Type Description
vector
Source: