RealVector

fibo edited this page Mar 9, 2013 · 8 revisions

Real Vector

source

Constructor

var algebra = require('algebra');

var Real       = algebra.Real.Element;
var RealVector = algebra.Real.Vector;
var Rn         = algebra.Real.VectorSpace;

var R3 = new Rn(3);

Example

var arg = {};
arg.elements = [];
arg.space = R3;

for (var i = 0; i < R3.getDim(); i++) {
  var num = i * i + 1; // elements are 1, 2, 5
  var element = new Real(num);
  arg.elements.push(element);
}

var vector = new RealVector(arg);

#Inheritance

Is a Vector.

Methods

clone()

eq(Vector)

getElements()

Returns the vector elements.

var zero = new Real(0);
var vector = new R3.Vector(zero, 1, 2);
var elements = vector.getElements();

console.log(elements[0].num()); // 0
console.log(elements[1].num()); // 1
console.log(elements[2].num()); // 2

getElement()

Returns the vector elements.

var zero = new Real(0);
var vector = new R3.Vector(zero, 1, 2);
var element = vector.getElement(0);
console.log(element.num()); // 0

scalar(number|Real)

Implements multiplication by a scalar.

var vector = new R3.Vector(1, 1, 1);

var two = new Real(2);
vector.scalar(two);

console.log(vector.x(0)); // 2
console.log(vector.x(1)); // 2
console.log(vector.x(2)); // 2

Coerces number type

var vector = new R3.Vector(1, 1, 1);

vector.scalar(2);

console.log(vector.x(0)); // 2
console.log(vector.x(1)); // 2
console.log(vector.x(2)); // 2

Can be chained.

dot(Vector)

Implements dot product operator.

var v1 = new R3.Vector(0, 0, 1);
var v2 = new R3.Vector(0, 1, 0);

var zero = v1.dot(v2);

console.log(zero.num()); // 0

R3 Vector

cross(Vector)

Implements cross product operator.

var v1 = new R3.Vector(0, 0, 1);
var v2 = new R3.Vector(0, 1, 0);

v1.cross(v2);

console.log(v1.x(0)); // -1
console.log(v1.x(1)); //  0
console.log(v1.x(2)); //  0

#add(Vector)

Implements vector addition operation.

var vector1 = new R3.Vector(1, 2, 3);
var vector2 = new R3.Vector(1, -1, 1);

vector1.add(vector2);

console.log(vector1.x(0)); // 2
console.log(vector1.x(1)); // 1
console.log(vector1.x(2)); // 4

Can be chained.

sub(Vector)

Implements vector subtraction operation.

var vector1 = new R3.Vector(1, 2, 3);
var vector2 = new R3.Vector(1, -1, 1);

vector1.sub(vector2);

console.log(vector1.x(0)); // 0
console.log(vector1.x(1)); // 3
console.log(vector1.x(2)); // 2

Can be chained.

ortho(Vector)

Returns true if two vectors are orthogonal.

var vector1 = new R3.Vector(1, 0, 1);
var vector2 = new R3.Vector(0, 1, 0);

console.ok(vector1.ortho(vector2)); // true

r4c(Matrix)

Implements right multiplication by matrix.

getCoordinates()

Returns an array of numbers.

var vector = new R3.Vector(1, 2, 3);

console.log(vector.getCoordinates()); // [1, 2, 3]

getCoordinate(Integer)

Returns the i-esim coordinate.

  var vector = new R3.Vector(1, 2, 3);
  console.log(vector.getCoordinate(0)); // 1
  console.log(vector.getCoordinate(1)); // 2
  console.log(vector.getCoordinate(2)); // 3

x(Integer)

Is an alias of getCoordinate(Integer)