Class

Vector

Inheritance
< Object
Included Modules
ExceptionForMatrix

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

Class

Visibility Signature
public [] (*array)
public elements (array, copy = true)
public new (method, array, copy)

Instance

Visibility Signature
public * (x)
public + (v)
public - (v)
public == (other)
public [] (i)
public clone ()
public coerce (other)
public collect ( {|e| ...}
public collect2 (v) {|e1, e2| ...}
public compare_by (elements)
public covector ()
public each2 (v) {|e1, e2| ...}
public eqn? (other)
public hash ()
public init_elements (array, copy)
public inner_product (v)
public inspect ()
public map (
public map2 (v) {|e1, e2| ...}
public r ()
public size ()
public to_a ()
public to_s ()

Class Method Detail

[](*array)

Creates a Vector from a list of elements.

  Vector[7, 4, ...]

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.

new(method, array, copy)

For internal use.

Instance Method Detail

*(x)

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

+(v)

Vector addition.

-(v)

Vector subtraction.

==(other)

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

[](i)

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

clone()

Return a copy of the vector.

coerce(other)

FIXME: describe Vector#coerce.

collect( {|e| ...}

collect2(v) {|e1, e2| ...}

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

compare_by(elements)

For internal use.

covector()

Creates a single-row matrix from this vector.

each2(v) {|e1, e2| ...}

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

eqn?(other)

Alias for #==

hash()

Return a hash-code for the vector.

init_elements(array, copy)

For internal use.

inner_product(v)

Returns the inner product of this vector with the other.

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

inspect()

Overrides Object#inspect

map(

Alias for collect

map2(v) {|e1, e2| ...}

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

r()

Returns the modulus (Pythagorean distance) of the vector.

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

size()

Returns the number of elements in the vector.

to_a()

Returns the elements of the vector in an array.

to_s()

Overrides Object#to_s