class Apatite::LinearAlgebra::Vector(T)

Overview

Represents a mathematical vector, and also constitutes a row or column of a Matrix

Included Modules

Defined in:

apatite/linear_algebra/vector.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.[](*array) #

Creates a new vector from a list of elements.


[View source]
def self.basis(size, index) #

Returns a standard basis n-vector.


[View source]
def self.elements(array, copy = true) #

Creates a vector from an Array. The optional second argument specifies whether the array itself or a copy is used internally.


[View source]
def self.independent?(*vs) #

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

[View source]
def self.zero(size) #

Return a zero vector.


[View source]

Instance Method Detail

def *(x : Number) #

Multiplies the vector by x, where x is a number.


[View source]
def *(x : Vector) #

Multiplies the vector by x, where x is another vector.


[View source]
def *(x : Matrix) #

Multiplies the vector by x, where x is a matrix.


[View source]
def +(x : Matrix) #

Vector addition.


[View source]
def +(x : Number) #

Vector addition.


[View source]
def +(x : Vector) #

Vector addition.


[View source]
def -(x : Matrix) #

Vector subtraction.


[View source]
def -(x : Vector) #

Vector subtraction.


[View source]
def -(x : Number) #

Vector subtraction.


[View source]
def /(x : Matrix) #

Vector division.


[View source]
def /(x : Number) #

Vector division.


[View source]
def /(x : Vector) #

Vector division.


[View source]
def <=>(other) #

Take me to your leader


[View source]
def <=>(other : Vector | Indexable) #

Alien mothership


[View source]
def ==(other) #

Equality operator


[View source]
def angle_with(v) #

Returns an angle with another vector. Result is within the [0…Math::PI].


[View source]
def clone #

Returns a copy of the vector.


[View source]
def coerce(klass : BigRational.class, denominator : Int) #

Attempt to coerce the elements in a vector to BigRational with the given denominator.


[View source]
def 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.


[View source]
def coerce(klass : BigInt.class, base = 10) #

Attempt to coerce the elements in a vector to BigInt with an optional base value.


[View source]
def coerce(klass : Complex.class, imag : Number) #

Attempt to coerce the elements in a vector to Complex with imag as the imaginary number.


[View source]
def covector #

Creates a single-row matrix from this vector.


[View source]
def cross(v) #

Returns the cross product of this vector with the others.


[View source]
def cross_product(*vs) #

Returns the cross product of this vector with the others.


[View source]
def dot(v) #

Returns the inner product of this vector with the other.


[View source]
def each(*args, **options, &block) #

[View source]
def each(v, &block) #

Iterate over the elements of this vector and v in conjunction.


[View source]
def each(*args, **options) #

[View source]
def inner_product(v) #

Returns the inner product of this vector with the other.


[View source]
def inspect #

[View source]
def magnitude #

Returns the modulus (Pythagorean distance) of the vector.


[View source]
def map(&block : T -> UNDERSCORE) #

Maps over a vector, passing each element to the block


[View source]
def 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


[View source]
def norm #

Returns the modulus (Pythagorean distance) of the vector.


[View source]
def normalize #

Returns a new vector with the same direction but with norm 1


[View source]
def r #

Returns a new vector with the same direction but with norm 1


[View source]
def round(ndigits = 0) #

Returns a vector with entries rounded to the given precision.


[View source]
def to_a #

Returns the elements of the vector in an array.


[View source]
def to_matrix #

Return a single-column matrix from this vector.


[View source]
def to_s #

[View source]
def unsafe_fetch(i) #

[View source]
def zero? #

Returns true if all elements are zero.


[View source]