Class Vector
In: lib/matrix.rb
Parent: Object

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:

  • [](i)

To enumerate the elements:

  • each2(v)
  • collect2(v)

Vector arithmetic:

  • *(x) "is matrix or number"
  • +(v)
  • -(v)

Vector functions:

Conversion to other data types:

String representations:

Methods

*   +   -   ==   []   []   clone   coerce   collect   collect2   compare_by   covector   each2   elements   eql?   hash   init_elements   inner_product   inspect   map   map2   new   r   size   to_a   to_s  

Included Modules

ExceptionForMatrix

Public Class methods

Creates a Vector from a list of elements.

  Vector[7, 4, ...]

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

For internal use.

Public Instance methods

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

Vector addition.

Vector subtraction.

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

Returns element number i (starting at zero) of the vector.

Return a copy of the vector.

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

For internal use.

Creates a single-row matrix from this vector.

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

eql?(other)

Alias for #==

Return a hash-code for the vector.

Returns the inner product of this vector with the other.

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

Alias for collect

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

Returns the modulus (Pythagorean distance) of the vector.

  Vector[5,8,2].r => 9.643650761

Returns the number of elements in the vector.

Returns the elements of the vector in an array.

[Validate]

ruby-doc.org is a service of James Britt and Neurogami, a Ruby application development company in Phoenix, AZ.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.