matrix_reloaded v2.2.1 MatrixReloaded.Vector View Source
Provides a set of functions to work with vectors.
Mostly functions is written for a row vectors. So if you'll need a similar
functionality even for a column vectors you can use transpose function
on row vector.
Link to this section Summary
Functions
Addition of two a row vectors. These two vectors must have a same size. Otherwise you get an error message
Create row vector of alternating sequence of numbers
Create a column vector of the specified size. Default values of vector
is set to 0. This value can be changed
Scalar product of two a row vectors. These two vectors must have a same size. Otherwise you get an error message
Inner product of two a row vectors. It produces a row vector where each
element i, j is the product of elements i, j of the original two
row vectors. These two vectors must have a same size. Otherwise you get
an error message
Multiply a vector by number
Outer product of two a row vectors. It produces a matrix of dimension
{m, n} where m and n are length (size) of row vectors. If input
vectors aren't a row type you get an error message
Create a row vector of the specified size. Default values of vector
is set to 0. This value can be changed
The size of the vector
Subtraction of two a row vectors. These two vectors must have a same size. Otherwise you get an error message
Convert (transpose) a row vector to column and vice versa
Update row vector by given a row subvector (list) of numbers or just by one number. The vector elements you want to change are given by the index. The index is a non-negative integer and determines the position of the element in the vector
Update row vector by given a row subvector (list) of numbers or by one number. The elements you want to change are given by the vector of indices. These indices must be a non-negative integers and determine the positions of the element in the vector
Link to this section Types
column()
View Source
column() :: [[number()]]
column() :: [[number()]]
subvector() View Source
t()
View Source
t() :: [number()]
t() :: [number()]
Link to this section Functions
add(vec1, vec2) View Source
Addition of two a row vectors. These two vectors must have a same size. Otherwise you get an error message.
Returns result, it means either tuple of {:ok, vector} or {:error, "msg"}.
Examples
iex> MatrixReloaded.Vector.add([1, 2, 3], [4, 5, 6])
{:ok, [5, 7, 9]}
alternate_seq(vec, val, step \\ 2)
View Source
alternate_seq(t(), number(), pos_integer()) :: t()
alternate_seq(t(), number(), pos_integer()) :: t()
Create row vector of alternating sequence of numbers.
Examples
iex> MatrixReloaded.Vector.row(5) |> MatrixReloaded.Vector.alternate_seq(1)
[1, 0, 1, 0, 1]
iex> MatrixReloaded.Vector.row(7) |> MatrixReloaded.Vector.alternate_seq(1, 3)
[1, 0, 0, 1, 0, 0, 1]
col(size, val \\ 0)
View Source
col(pos_integer(), number()) :: column()
col(pos_integer(), number()) :: column()
Create a column vector of the specified size. Default values of vector
is set to 0. This value can be changed.
Returns list of list number.
Examples
iex> MatrixReloaded.Vector.col(3)
[[0], [0], [0]]
iex> MatrixReloaded.Vector.col(3, 4)
[[4], [4], [4]]
dot(vec1, vec2) View Source
Scalar product of two a row vectors. These two vectors must have a same size. Otherwise you get an error message.
Returns result, it means either tuple of {:ok, number} or {:error, "msg"}.
Examples
iex> MatrixReloaded.Vector.dot([1, 2, 3], [4, 5, 6])
{:ok, 32}
inner_product(vec1, vec2) View Source
Inner product of two a row vectors. It produces a row vector where each
element i, j is the product of elements i, j of the original two
row vectors. These two vectors must have a same size. Otherwise you get
an error message.
Returns result, it means either tuple of {:ok, vector} or {:error, "msg"}.
Examples
iex> MatrixReloaded.Vector.inner_product([1, 2, 3], [4, 5, 6])
{:ok, [4, 10, 18]}
mult_by_num(vec, val) View Source
Multiply a vector by number.
Examples
iex> MatrixReloaded.Vector.row(3, 2) |> MatrixReloaded.Vector.mult_by_num(3)
[6, 6, 6]
iex> MatrixReloaded.Vector.col(3, 2) |> MatrixReloaded.Vector.mult_by_num(3)
[[6], [6], [6]]
outer_product(vec1, vec2)
View Source
outer_product(t(), t()) :: Result.t(String.t(), MatrixReloaded.Matrix.t())
outer_product(t(), t()) :: Result.t(String.t(), MatrixReloaded.Matrix.t())
Outer product of two a row vectors. It produces a matrix of dimension
{m, n} where m and n are length (size) of row vectors. If input
vectors aren't a row type you get an error message.
Returns result, it means either tuple of {:ok, matrix} or {:error, "msg"}.
Examples
iex> MatrixReloaded.Vector.outer_product([1, 2, 3, 4], [1, 2, 3])
{:ok,
[
[1, 2, 3],
[2, 4, 6],
[3, 6, 9],
[4, 8, 12]
]
}
row(size, val \\ 0)
View Source
row(pos_integer(), number()) :: t()
row(pos_integer(), number()) :: t()
Create a row vector of the specified size. Default values of vector
is set to 0. This value can be changed.
Returns list of numbers.
Examples
iex> MatrixReloaded.Vector.row(4)
[0, 0, 0, 0]
iex> MatrixReloaded.Vector.row(4, 3.9)
[3.9, 3.9, 3.9, 3.9]
size(vec)
View Source
size(t()) :: non_neg_integer()
size(t()) :: non_neg_integer()
The size of the vector.
Returns a positive integer.
Example:
iex> MatrixReloaded.Vector.row(3) |> MatrixReloaded.Vector.size()
3
iex> MatrixReloaded.Vector.col(4, -1) |> MatrixReloaded.Vector.size()
4
sub(vec1, vec2) View Source
Subtraction of two a row vectors. These two vectors must have a same size. Otherwise you get an error message.
Returns result, it means either tuple of {:ok, vector} or {:error, "msg"}.
Examples
iex> MatrixReloaded.Vector.sub([1, 2, 3], [4, 5, 6])
{:ok, [-3, -3, -3]}
transpose(vec) View Source
Convert (transpose) a row vector to column and vice versa.
Examples
iex> MatrixReloaded.Vector.transpose([1, 2, 3])
[[1], [2], [3]]
iex(23)> MatrixReloaded.Vector.transpose([[1], [2], [3]])
[1, 2, 3]
update(vec, subvec, index) View Source
Update row vector by given a row subvector (list) of numbers or just by one number. The vector elements you want to change are given by the index. The index is a non-negative integer and determines the position of the element in the vector.
Returns result, it means either tuple of {:ok, vector} or {:error, "msg"}.
Example:
iex> vec = 0..10 |> Enum.to_list()
iex> MatrixReloaded.Vector.update(vec, [0, 0, 0], 5)
{:ok, [0, 1, 2, 3, 4, 0, 0, 0, 8, 9, 10]}
iex> vec = 0..10 |> Enum.to_list()
iex> MatrixReloaded.Vector.update(vec, 0, 5)
{:ok, [0, 1, 2, 3, 4, 0, 6, 7, 8, 9, 10]}
update_map(vec, subvec, position_indices) View Source
Update row vector by given a row subvector (list) of numbers or by one number. The elements you want to change are given by the vector of indices. These indices must be a non-negative integers and determine the positions of the element in the vector.
Returns result, it means either tuple of {:ok, vector} or {:error, "msg"}.
Example:
iex> vec = 0..10 |> Enum.to_list()
iex> MatrixReloaded.Vector.update_map(vec, [0, 0], [2, 7])
{:ok, [0, 1, 0, 0, 4, 5, 6, 0, 0, 9, 10]}
iex> vec = 0..10 |> Enum.to_list()
iex> MatrixReloaded.Vector.update_map(vec, 0, [2, 7])
{:ok, [0, 1, 0, 3, 4, 5, 6, 0, 8, 9, 10]}