vec_helpers: Vector Helper Functions

Description Usage Arguments Value Examples

Description

These simple functions perform common computations on vectors: l1 and l2 norms, unit length normalization, dot products, and angles.

Usage

1
2
3
4
5
6
7
8
9
l1(v)

l2(v)

normalize(v)

dot(v1, v2)

angle(v1, v2)

Arguments

v, v1, v2

Numeric vectors or 1 x n matrices. For the binary functions, v1 and v2 must have the same length (if vectors) or number of rows (if matrices).

Value

l1 returns the l1 norm of the vector.

l2 returns the l2 norm of the vector.

normalize returns the vector normalized to unit length, or an error if passed the zero vector.

dot returns the dot product of two vectors.

angle returns the angle between the two vectors in radians.

Examples

1
2
3
4
5
dot(c(2, -1), c(1, 2))
angle(c(1, 0), c(0, 1))
normalize(rep(1, 16))
l1(-2:2)
l2(-2:2)

ryan-heslin/matador documentation built on Dec. 22, 2021, 8:17 p.m.