class Apatite::LinearAlgebra::Vector(T)
- Apatite::LinearAlgebra::Vector(T)
- Reference
- Object
Overview
Represents a mathematical vector, and also constitutes a row or column
of a Matrix
Included Modules
- Comparable(Apatite::LinearAlgebra::Vector(T))
- Enumerable(T)
- Indexable(T)
Defined in:
apatite/linear_algebra/vector.crClass Method Summary
-
.[](*array)
Creates a new vector from a list of elements.
-
.basis(size, index)
Returns a standard basis
n
-vector. -
.elements(array, copy = true)
Creates a vector from an Array.
-
.independent?(*vs)
Returns
true
if all of vectors are linearly independent. -
.zero(size)
Return a zero vector.
Instance Method Summary
-
#*(x : Number)
Multiplies the vector by x, where x is a number.
-
#*(x : Vector)
Multiplies the vector by x, where x is another vector.
-
#*(x : Matrix)
Multiplies the vector by x, where x is a matrix.
-
#+(x : Matrix)
Vector addition.
-
#+(x : Number)
Vector addition.
-
#+(x : Vector)
Vector addition.
-
#-(x : Matrix)
Vector subtraction.
-
#-(x : Vector)
Vector subtraction.
-
#-(x : Number)
Vector subtraction.
-
#/(x : Matrix)
Vector division.
-
#/(x : Number)
Vector division.
-
#/(x : Vector)
Vector division.
-
#<=>(other)
Take me to your leader
-
#<=>(other : Vector | Indexable)
Alien mothership
-
#==(other)
Equality operator
-
#angle_with(v)
Returns an angle with another vector.
-
#clone
Returns a copy of the vector.
-
#coerce(klass : BigRational.class, denominator : Int)
Attempt to coerce the elements in a vector to BigRational with the given
denominator
. -
#coerce(klass : U.class) : Apatite::LinearAlgebra::Vector(U) forall U
The coerce method allows you to attempt to coerce the elements in the matrix to another type.
-
#coerce(klass : BigInt.class, base = 10)
Attempt to coerce the elements in a vector to BigInt with an optional
base
value. -
#coerce(klass : Complex.class, imag : Number)
Attempt to coerce the elements in a vector to Complex with
imag
as the imaginary number. -
#covector
Creates a single-row matrix from this vector.
-
#cross(v)
Returns the cross product of this vector with the others.
-
#cross_product(*vs)
Returns the cross product of this vector with the others.
-
#dot(v)
Returns the inner product of this vector with the other.
- #each(*args, **options, &block)
-
#each(v, &block)
Iterate over the elements of this vector and
v
in conjunction. - #each(*args, **options)
-
#inner_product(v)
Returns the inner product of this vector with the other.
- #inspect
-
#magnitude
Returns the modulus (Pythagorean distance) of the vector.
-
#map(&block : T -> UNDERSCORE)
Maps over a vector, passing each element to the block
-
#map(v, &block : T, T -> UNDERSCORE)
Maps over the current vector and
v
in conjunction, passing each element in each to the block and returning a new vector -
#norm
Returns the modulus (Pythagorean distance) of the vector.
-
#normalize
Returns a new vector with the same direction but with norm 1
-
#r
Returns a new vector with the same direction but with norm 1
-
#round(ndigits = 0)
Returns a vector with entries rounded to the given precision.
-
#to_a
Returns the elements of the vector in an array.
-
#to_matrix
Return a single-column matrix from this vector.
- #to_s
- #unsafe_fetch(i)
-
#zero?
Returns
true
if all elements are zero.
Class Method Detail
Creates a vector from an Array. The optional second argument specifies whether the array itself or a copy is used internally.
Returns true
if all of vectors are linearly independent.
Vector.independent?(Vector[1,0], Vector[0,1])
# => true
Vector.independent?(Vector[1,2], Vector[2,4])
# => false
Instance Method Detail
Attempt to coerce the elements in a vector to BigRational
with the given denominator
.
The coerce method allows you to attempt to coerce the elements in the matrix to another type.
Attempt to coerce the elements in a vector to BigInt with
an optional base
value.
Attempt to coerce the elements in a vector to Complex with
imag
as the imaginary number.
Maps over the current vector and v
in conjunction, passing each
element in each to the block and returning a new vector