matrix_reloaded v1.0.2 MatrixReloaded.Vector
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
Link to this section Types
t()
t() :: [number()]
t() :: [number()]
Link to this section Functions
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)
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)
col(pos_integer(), number()) :: [t()]
col(pos_integer(), number()) :: [t()]
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]]
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)
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)
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)
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)
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)
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
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)
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]