# 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
Type Description
number
Source:

#### (static) abs_squared(a) → {number}

Length of a vector, squared.

##### Parameters:
Name Type Description
`a` vector
Type Description
number
Source:

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

##### Parameters:
Name Type Description
`a` vector
`b` vector
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
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
Type Description
vector
Source:

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

Divide by a scalar.

##### Parameters:
Name Type Description
`v` vector
`k` number
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
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
Type Description
boolean
Source:

#### (static) is_zero(v) → {boolean}

Is every component of this vector zero?

##### Parameters:
Name Type Description
`v` vector
Type Description
boolean
Source:

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

Apply given function to each element.

##### Parameters:
Name Type Description
`v` vector
`fn` function
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
Type Description
vector
Source:

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

Multiply by a scalar.

##### Parameters:
Name Type Description
`k` number
`v` vector
Type Description
vector
Source:

#### (static) negate(v) → {vector}

Negate a vector - negate each of its components.

##### Parameters:
Name Type Description
`v` vector
Type Description
vector
Source:

#### (static) neq(a, b) → {boolean}

Are two vectors unequal?

##### Parameters:
Name Type Description
`a` vector
`b` vector
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.

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.

Type Description
vector
Source:

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

Subtract one vector from another.

##### Parameters:
Name Type Description
`a` vector
`b` vector
Type Description
vector
Source:

#### (static) toMatrix(v) → {matrix}

Convert a vector to a 1-column matrix.

##### Parameters:
Name Type Description
`v` vector
Type Description
matrix
Source:

#### (static) transpose(v) → {matrix}

Transpose of a vector.

##### Parameters:
Name Type Description
`v` vector
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
Type Description
vector
Source: