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   component   covector   each2   element   elements   elements_to_f   elements_to_i   elements_to_r   eqn?   hash   init_elements   inner_product   inspect   map   map2   new   r   set_component   set_element   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.

component(i)

Alias for #[]

Creates a single-row matrix from this vector.

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

element(i)

Alias for #[]

eqn?(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
set_component(i, v)

Alias for #[]=

set_element(i, v)

Alias for #[]=

Returns the number of elements in the vector.

Returns the elements of the vector in an array.

[Validate]

ruby-doc.org is hosted and maintained by James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, Arizona. The site was created in 2002 as part of the Ruby Documentation Project to promote the Ruby language and to help other Ruby hackers.

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.