Class

The Vector class represents a mathematical vector, which is useful in its own right, and also constitutes a row or column of a Matrix.

Method Catalogue

To create a Vector:

To access elements:

To set elements:

To enumerate the elements:

Properties of vectors:

Vector arithmetic:

Vector functions:

Conversion to other data types:

String representations:

Attributes
Read

INSTANCE CREATION

Class Methods

Creates a Vector from a list of elements.

Vector[7, 4, ...]

Returns a standard basis n-vector, where k is the index.

Vector.basis(size:, index:) # => Vector[0, 1, 0]

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

Returns true iff all of vectors are linearly independent.

Vector.independent?(Vector[1,0], Vector[0,1])
  => true

Vector.independent?(Vector[1,2], Vector[2,4])
  => false

Vector.new is private; use Vector[] or Vector.elements to create.

Return a zero vector.

Vector.zero(3) => Vector[0, 0, 0]
Instance Methods

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

Vector addition.

No documentation available

Vector subtraction.

No documentation available

Vector division.

Returns true iff the two vectors have the same elements in the same order.

Returns element or elements of the vector.

Set element or elements of vector.

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

Vector[1,0].angle_with(Vector[0,1])
# => Math::PI / 2

The coerce method provides support for Ruby type coercion. This coercion mechanism is used by Ruby to handle mixed-type numeric operations: it is intended to find a compatible common type between the two operands of the operator. See also Numeric#coerce.

Collects (as in Enumerable#collect) over the elements of this vector and v in conjunction.

Creates a single-row matrix from this vector.

An alias for cross_product

Returns the cross product of this vector with the others.

Vector[1, 0, 0].cross_product Vector[0, 1, 0]   => Vector[0, 0, 1]

It is generalized to other dimensions to return a vector perpendicular to the arguments.

Vector[1, 2].cross_product # => Vector[-2, 1]
Vector[1, 0, 0, 0].cross_product(
   Vector[0, 1, 0, 0],
   Vector[0, 0, 1, 0]
)  #=> Vector[0, 0, 0, 1]
An alias for inner_product

Iterate over the elements of this vector

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

No documentation available
No documentation available
No documentation available
No documentation available
No documentation available

Returns a hash-code for the vector.

Returns true iff all of vectors are linearly independent.

Vector[1,0].independent?(Vector[0,1])
  => true

Vector[1,2].independent?(Vector[2,4])
  => false

Called for dup & clone.

Returns the inner product of this vector with the other.

Vector[4,7].inner_product Vector[10,1]  => 47

Overrides Object#inspect

Returns the modulus (Pythagorean distance) of the vector.

Vector[5,8,2].r => 9.643650761
An alias for collect
An alias for collect!

Like Vector#collect2, but returns a Vector instead of an Array.

An alias for magnitude

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

v = Vector[5,8,2].normalize
# => Vector[0.5184758473652127, 0.8295613557843402, 0.20739033894608505]
v.norm => 1.0
#
An alias for magnitude

Returns a vector with entries rounded to the given precision (see Float#round)

An alias for []=
An alias for []=
No documentation available
No documentation available

Returns the number of elements in the vector.

Returns the elements of the vector in an array.

Return a single-column matrix from this vector

Overrides Object#to_s

Returns true iff all elements are zero.