exalgebra v0.0.2 ExAlgebra.Vector

ExAlgebra.Vector contains functions used in vector algebra.

Summary

Functions

Returns the addition of two vectors. ## Examples

Returns an orthogonal basis from a set of linearly independent vectors. ## Examples

Returns an orthogonal vector from a vector and a set of linearly independent vectors. ## Examples

Returns an orthonormal basis from a set of linearly independent vectors. This uses the modified Gram Schmidt algorithm. ## Examples

Returns the distance between two vectors. ## Examples

Returns the dot product of two vectors. ## Examples

Returns true if and only if a set of vectors are linearly independent. ## Examples

Returns true iff two vectors are orthogonal. ## Examples

Returns the magnitude of a vector. ## Examples

Returns the normalization of a vector. ## Examples

Returns the projection of one vector by another. ## Examples

Returns the multiple of a vector by a scalar. ## Examples

Returns the square of the magnitude of a vector. ## Examples

Returns the subtraction of two vectors. ## Examples

Functions

add(list1, list2)

Specs

add([number], [number]) :: [number]

Returns the addition of two vectors. ## Examples

iex> vector = [1, 2, 3]
[1, 2, 3]

iex> vector |> ExAlgebra.Vector.add([2, 3, 4])
[3, 5, 7]
create_orthogonal_basis(linearly_independent_vectors)

Specs

create_orthogonal_basis([[number]]) :: [[number]]
create_orthogonal_basis([[number]]) :: [[number]]

Returns an orthogonal basis from a set of linearly independent vectors. ## Examples

iex> vectors = [[1, 2, 4, 0], [0, 1, 1, 0], [0, 3, 1, 4]]
[[1, 2, 4, 0], [0, 1, 1, 0], [0, 3, 1, 4]]

iex> vectors |> ExAlgebra.Vector.create_orthogonal_basis
[[1, 2, 4, 0], [-2/7, 3/7, -1/7, 0], [2/3, 1/3, -1/3, 4]]
create_orthogonal_vector(vector, linearly_independent_vectors)

Returns an orthogonal vector from a vector and a set of linearly independent vectors. ## Examples

iex> vector = [0, 1, 1, 0]
[0, 1, 1, 0]

iex> vector |> ExAlgebra.Vector.create_orthogonal_vector([[1, 2, 4, 0]])
[-2/7, 3/7, -1/7, 0]
create_orthonormal_basis(linearly_independent_vectors)

Returns an orthonormal basis from a set of linearly independent vectors. This uses the modified Gram Schmidt algorithm. ## Examples

iex> vectors = [[1, 1, 1], [2, 1, 0], [5, 1, 3]]
[[1, 1, 1], [2, 1, 0], [5, 1, 3]]

iex> vectors |> ExAlgebra.Vector.create_orthonormal_basis
[[0.57735026919, 0.57735026919, 0.57735026919], [0.70710678118, 0, -0.70710678118], [0.40824829046, -0.81649658092, 0.40824829046]]
distance(vector_one, vector_two)

Specs

distance([number], [number]) :: number

Returns the distance between two vectors. ## Examples

iex> vector = [1, 2, 3]
[1, 2, 3]

iex> vector |> ExAlgebra.Vector.sqr_magnitude([4, 5, 6])
5.1961524227
dot(list1, list2)

Specs

dot([number], [number]) :: number

Returns the dot product of two vectors. ## Examples

iex> vector = [1, 2, 3]
[1, 2, 3]

iex> vector |> ExAlgebra.Vector.dot([2, 3, 4])
[2, 6, 12]
is_linearly_independent?(vectors)

Specs

is_linearly_independent?([[number]]) :: boolean

Returns true if and only if a set of vectors are linearly independent. ## Examples

iex> vectors = [[1, 1, 1], [2, 1, 0], [5, 1, 3]]
[[1, 1, 1], [2, 1, 0], [5, 1, 3]]

iex> vector |> ExAlgebra.Vector.is_linearly_independent?
true

iex> vectors = [[2, 3, 5], [-1, -4, -10], [1, -2, -8]]
[[2, 3, 5], [-1, -4, -10], [1, -2, -8]]

iex> vector |> ExAlgebra.Vector.is_linearly_independent?
false
is_orthogonal?(vector_one, vector_two)

Specs

is_orthogonal?([number], [number]) :: boolean

Returns true iff two vectors are orthogonal. ## Examples

iex> vector = [1, 1, 1]
[1, 1, 1]

iex> vector |> ExAlgebra.Vector.is_orthogonal?([-2, 1, 1])
true

iex> vector = [1, 1, 1]
[1, 1, 1]

iex> vector |> ExAlgebra.Vector.is_orthogonal?([1, 1, 1])
false 
magnitude(vector)

Specs

magnitude([number]) :: number

Returns the magnitude of a vector. ## Examples

iex> vector = [1, 2, 3, 4]
[1, 2, 3, 4]

iex> vector |> ExAlgebra.Vector.magnitude
5.4772255751
normalize(vector)

Specs

normalize([number]) :: [number]

Returns the normalization of a vector. ## Examples

iex> vector = [1, 2, 3, 4]
[1, 2, 3, 4]

iex> vector |> ExAlgebra.Vector.sqr_magnitude
[0.1825741858, 0.3651483717, 0.5477225575, 0.7302967433]
project(vector_one, vector_two)

Specs

project([number], [[number]]) :: [number]
project([number], [number]) :: [number]

Returns the projection of one vector by another. ## Examples

iex> vector = [1, 2, 4, 0]
[1, 2, 4, 0]

iex> vector |> ExAlgebra.Vector.project([0, 1, 1, 0])
[2/7, 4/7, 8/7, 0]
scalar_multiply(vector, scalar)

Specs

scalar_multiply([number], number) :: [number]

Returns the multiple of a vector by a scalar. ## Examples

iex> vector = [1, 2, 3]
[1, 2, 3]

iex> vector |> ExAlgebra.Vector.scalar_multiply(2.5)
[2.5, 5, 7.5]
sqr_magnitude(vector)

Specs

sqr_magnitude([number]) :: number

Returns the square of the magnitude of a vector. ## Examples

iex> vector = [1, 2, 3, 4]
[1, 2, 3, 4]

iex> vector |> ExAlgebra.Vector.sqr_magnitude
30
subtract(list1, list2)

Specs

subtract([number], [number]) :: [number]

Returns the subtraction of two vectors. ## Examples

iex> vector = [1, 2, 3]
[1, 2, 3]

iex> vector |> ExAlgebra.Vector.subtract([2, 3, 4])
[-1, -1, -1]