Class: Vector

JSMatrix. Vector

Represents a vector (1D matrix) of real (floating point) numbers

new Vector(nElements)

Vector implementation
This:
Parameters:
Name Type Argument Description
nElements number <optional>
(default=0) number of elements of newly created Vector object
Properties:
Name Type Description
nElements number Number of vector elements
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 105

Methods

<static> canMultiplyMatFromLeft()

Alias for canMultiplyMat(), see JSMatrix.Vector#canMultiplyMat
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 355

<static> create(arry) → {JSMatrix.Vector}

Constructs new Vector from given array
Parameters:
Name Type Description
arry Array.<number> (default=[]) array containing elements of new vector
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1231
Returns:
new Vector object
Type
JSMatrix.Vector
Example
v = JSMatrix.Vector.create([1,2,3,4]); // v = Vector([1,2,3,4])

<static> Ones(nElements) → {JSMatrix.Vector}

Creates a vector full of ones
Parameters:
Name Type Argument Description
nElements number <optional>
=0] number of elements
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1278
Returns:
new vector full of zeros
Type
JSMatrix.Vector
Example
v = JSMatrix.Vector.Ones(6); // v = Vector([1,1,1,1,1,1])

<static> UnitX() → {JSMatrix.Vector}

Creates unit vector in x direction
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1245
Returns:
unit x vector
Type
JSMatrix.Vector
Example
v = JSMatrix.Vector.UnitX(); // v = Vector([1,0,0])

<static> UnitY() → {JSMatrix.Vector}

Creates unit vector in y direction
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1252
Returns:
unit y vector
Type
JSMatrix.Vector
Example
v = JSMatrix.Vector.UnitY(); // v = Vector([0,1,0])

<static> UnitZ() → {JSMatrix.Vector}

Creates unit vector in z direction
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1259
Returns:
unit z vector
Type
JSMatrix.Vector
Example
v = JSMatrix.Vector.UnitZ(); // v = Vector([0,0,1])

<static> Zeros(nElements) → {JSMatrix.Vector}

Creates a vector full of zeros
Parameters:
Name Type Argument Description
nElements number <optional>
=0] number of elements
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1267
Returns:
new vector full of zeros
Type
JSMatrix.Vector
Example
v = JSMatrix.Vector.Zeros(4); // v = Vector([0,0,0,0])

abs() → {JSMatrix.Vector}

Returns Vector with elementwise abs value of receiver elements ( ret[i] = abs(this[i]) )
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 233
Returns:
elementwise absolute value of receiver
Type
JSMatrix.Vector
Example
v = JSMatrix.vec([1,-4,3,-2]);
m = v.abs(); // m = Vector([1,4,3,2])

add(vec) → {JSMatrix.Vector}

Returns sum of receiver and vector ( ret = this + vec )
Parameters:
Name Type Description
vec JSMatrix.Vector 2nd vector of the sum
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 390
Returns:
sum of receiver and vec
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([6,1,5]);
v4 = v1.add(v2); // v4 = Vector([7,3,8])

appendElements(newElems)

Appends given float/vector to the end of receiver
Parameters:
Name Type Description
newElems number | JSMatrix.Vector | Array.<JSMatrix.Vector> new element(s) to be appended
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1032
Example
v = JSMatrix.vec([1,2]);
v.appendElements(4); // v = Vector([1,2,4]);
v.appendElements(JSMatrix.vec([7,6])); // v = Vector([1,2,4,7,6]);
v.appendElements([JSMatrix.vec([1,2]),JSMatrix.vec([3,4])]); // v = Vector([1,2,4,6,7,1,2,3,4])

assemble(vec, coeffs)

assemble receiver to given vector ( vec[coeffs] += this )
Parameters:
Name Type Description
vec JSMatrix.Vector vector where receiver is assembled
coeffs Array.<number> | JSMatrix.Vector array containing coefficients of vec to be incremented
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 908
Example
v1 = JSMatrix.vec([5,8,2,4,3,5]);
v2 = JSMatrix.vec([1,2,3]);
v2.assemble(v1,[5,1,2]); // v1 = Vector([5,10,5,4,3,6])

beColOf(mat, c)

Modifies receiver to become column of given matrix - indexing from 0. Receiver's size is adjusted
Parameters:
Name Type Description
mat JSMatrix.Matrix given matrix
c number desired column (indexing from 0)
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 941
Example
v = JSMatrix.vec([1,2]);
m = JSMatrix.mat([[11,12,13],[21,22,23],[31,32,33]]);
v.beColOf(m,1) // v = Vector([12,22,32])

beColumnOf()

Alias for beColOf(), see JSMatrix.Vector#beColOf
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 951

beCopyOf(vec)

Modifies receiver to become copy of given vector (this = vec). Receiver's size is adjusted
Parameters:
Name Type Description
vec JSMatrix.Vector vector to be copied to receiver
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 983
Example
v1 = JSMatrix.vec([4,5]);
v2 = JSMatrix.vec([1,2,3]);
v1.beCopyOf(v2) // v2 = Vector([1,2,3])

beCrossProductOf(vec1, vec2)

Modifies receiver to become cross product of two vectors. Both given vectors have to be of length 3. Receiver's size is adjusted
Parameters:
Name Type Description
vec1 JSMatrix.Vector 1st vector for multiplication
vec2 JSMatrix.Vector 2nd vector for multiplication
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 622
Example
v = JSMatrix.vec([5,6]);
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([4,5,6]);
v.beCrossProductOf(v1,v2); // v = Vector([-3,6,-3])

beDiagonalFrom(mat)

Modifies receiver to contain diagonal elements of mat ( this = diag(mat) )
Parameters:
Name Type Description
mat JSMatrix.Matrix matrix whose diagonal is copied to receiver
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1184
Example
v = JSMatrix.vec([6,7]);
m = JSMatrix.mat([[1,2,3],[4,5,6],[7,8,9]]);
v.beDiagonalFrom(m); // v = Vector([1,5,9])

beDifferenceOf(vec1, vec2)

Modifies receiver to become difference of two vectors ( this = vec1 - vec2 ). Receiver's size is adjusted
Parameters:
Name Type Description
vec1 JSMatrix.Vector 1st vector of the difference
vec2 JSMatrix.Vector 2nd vector of the difference
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 463
Example
v = JSMatrix.vec([4,5]);
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([6,1,5]);
v.beDifferenceOf(v1,v2); // v = Vector([-5,1,-2])

beFullOfOnes()

Sets all elements of receiver to 1.0
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 168
Example
v = JSMatrix.vec([1,2,3,4]);
v.beFullOfOnes(); // v = Vector([1,1,1,1])

beNegativeOf(vec)

Modifies receiver to become negative of given vector (this = -vec). Receiver's size is adjusted
Parameters:
Name Type Description
vec JSMatrix.Vector given vector
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 667
Example
v1 = JSMatrix.vec([4,5])
v2 = JSMatrix.vec([1,2,3]);
v1.beNegativeOf(v2); // v1 = Vector([-1,-2,-3])

beProductOf(mat, vec)

Modifies receiver to become product of given matrix and vector ( this = mat * vec ). Receiver's size is adjusted
Parameters:
Name Type Description
mat JSMatrix.Matrix matrix of multiplication
vec JSMatrix.Vector vector of multiplication
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 749
Example
v = JSMatrix.vec([4,5]);
m = JSMatrix.mat([[11,12,13],[21,22,23],[31,32,33]]);
v1 = JSMatrix.vec([1,2,3]);
v.beProductOf(m,v1); // v = Vector([74,134,194])

beRowOf(mat, r)

Modifies receiver to become row of given matrix - indexing from 0. Receiver's size is adjusted
Parameters:
Name Type Description
mat JSMatrix.Matrix given matrix
r number desired row (indexing from 0)
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 926
Example
v = JSMatrix.vec([1,2]);
m = JSMatrix.mat([[11,12,13],[21,22,23],[31,32,33]]);
v.beRowOf(m,1) // v = Vector([21,22,23])

beSolutionOf(mat, rhs, method, saveOrig, precompDecomps)

Modifies receiver to be a solution of linear system of equations mat*this = rhs. Receiver's size is adjusted
Parameters:
Name Type Argument Description
mat JSMatrix.Matrix matrix of the system
rhs JSMatrix.Vector vector of right hand side
method string <optional>
="default"] see {@JSMatrix.Matrix#linSolve}
saveOrig boolean <optional>
=true] see {@JSMatrix.Matrix#linSolve}
precompDecomps Array.<JSMatrix.Matrix> <optional>
=undefined] see {@JSMatrix.Matrix#linSolve}
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1218
Example
v = JSMatrix.vec([2,3]);
a = JSMatrix.mat([[1,2,9],[8,3,2],[3,7,3]]);
b = JSMatrix.vec([32,20,26]);
v.beSolutionOf(a,b); // v = Vector([1,2,3])

beSubVectorOf(vec, coeffs)

Modifies receiver to become subvector of given vector (this = vec[coeffs]). Receiver's size is adjusted
Parameters:
Name Type Description
vec JSMatrix.Vector vector to get subvector from
coeffs Array.<number> | JSMatrix.Vector array containing coefficients of desired subvector
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 824
Example
v1 = JSMatrix.vec([4,7,9,1,8,3,2,4,6,7,5,1,6,9]);
v2 = JSMatrix.vec([3,4]);
v2.beSubVectorOf(v1,[2,3,6,8,9]); // v2 = Vector([9,1,2,6,7])

beSumOf(vec1, vec2)

Modifies receiver to become sum of two vectors ( this = vec1 + vec2 ). Receiver's size is adjusted
Parameters:
Name Type Description
vec1 JSMatrix.Vector 1st vector of the sum
vec2 JSMatrix.Vector 2nd vector of the sum
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 419
Example
v = JSMatrix.vec([3,4]);
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([6,1,5]);
v.beSumOf(v1,v2); // v = Vector([7,3,8])

beTProductOf(mat)

Modifies receiver to become product of given vector and matrix ( this = vec^T * mat )
Parameters:
Name Type Description
JSMatrix.vec JSMatrix.Vector vector of multiplication
mat JSMatrix.Matrix matrix of multiplication
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 774
Example
v= JSMatrix.vec([5,6]);
v1 = JSMatrix.vec([1,2,3]);
m = JSMatrix.mat([[11,12,13],[21,22,23],[31,32,33]])
v.beTProductOf(v1,m); // v = Vector([146,152,158])

canMultiplyMat(mat) → {boolean}

Testing if receiver can multiply given matrix from left ( this^T * mat )
Parameters:
Name Type Description
mat JSMatrix.Matrix matrix to be tested
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 348
Returns:
true if the multiplication is possible, false otherwise
Type
boolean
Example
v = JSMatrix.vec([1,2,3]);
m1 = JSMatrix.mat([[11,12,13],[21,22,23]]);
m2 = JSMatrix.mat([[11,12],[21,22],[31,32]]);
t1 = v.canMultiplyMat(m1); // t1 = true
t2 = v.canMultiplyMat(m2); // t2 = false

copied() → {JSMatrix.Vector}

Returns copy of receiver
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 964
Returns:
copy of receiver
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = v1;
v3 = v1.copied();
v1.set(1,6);
// v1; = Vector([1,6,3])
// v2; = Vector([1,6,3])
// v3; = Vector([1,2,3])

copy()

Alias for copied(), see JSMatrix.Vector#copied
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 974

cross(vec) → {JSMatrix.Vector}

Returns vector (cross) product of receiver and given vector. Both receiver and given vector have to be of length 3.
Parameters:
Name Type Description
vec JSMatrix.Vector 2nd vector of multiplication
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 605
Returns:
cross product of receiver and vec
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([4,5,6]);
v3 = v1.cross(v2); // v3 = Vector([-3,6,-3])

decrSubVector(coeffs, vec)

Decrement subvector at defined positions of receiver (this[coeffs] -= vec)
Parameters:
Name Type Description
coeffs Array.<number> | JSMatrix.Vector array containing coefficients to be decremented
vec JSMatrix.Vector vector to be subtracted
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 885
Example
v = JSMatrix.vec([4,7,9,1,8,3,2,4,6,7,5,1,6,9]);
v.decrSubVector([2,3,6,8,9],JSMatrix.vec([1.1,2.2,3.3,4.4,5.5])); // v = Vector([4,7,7.9,-1.2,8,3,-1.3,4,1.6,1.5,5,1,6,9])

decrsv()

Alias for decrSubVector, see JSMatrix.Vector#decrSubVector
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 898

diag(mat) → {JSMatrix.Matrix|undefined}

Returns matrix with receiver's elements on diagonal (if no argument is specified, seeJSMatrix.Vector#toDiagonalMatrix) or modifies receiver to contain diagonal elements of given matrix (if given matrix is specified, seeJSMatrix.Vector#beDiagonalFrom)
Parameters:
Name Type Argument Description
mat JSMatrix.Matrix <optional>
=undefined] matrix whose diagonal is copied to receiver. If not specified, diagnal matrix is returned
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1201
Returns:
if no input parameter, returns diagonal matrix, otherwise nothing
Type
JSMatrix.Matrix | undefined
Example
v = JSMatrix.vec([6,7]);
m1 = JSMatrix.mat([[1,2,3],[4,5,6],[7,8,9]]);
v.diag(m1); // v = Vector([1,5,9])
m2 = v.diag(); // m2 = Matrix([[1,0,0],[0,5,0],[0,0,9]])

dot(vec, n) → {number|null}

Returns dot (inner) product of receiver and given vector
Parameters:
Name Type Argument Description
vec JSMatrix.Vector vector for dot product
n number <optional>
=0] dot product will be made from first n elements. If not specified, zero or negative, all elements are used
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 480
Returns:
dot product of receiver and vec from first n elements
Type
number | null
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([6,1,5]);
d2 = v1.dot(v2,2); // d2 = 8

dyadic(vec) → {JSMatrix.Matrix}

Returns dyadic (tensor, outer, direct,..) product of receiver and given vector
Parameters:
Name Type Description
vec JSMatrix.Vector vector for multiplication
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 571
Returns:
dyadic product of receiver and vec
Type
JSMatrix.Matrix
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([4,5,6]);
m = v1.dyadic(v2); // m = Matrix([[4,5,6],[8,10,12],[12,15,18]])

elementsPermutation(coeffs, backward) → {JSMatrix.Vector}

Returns permutated copy of receiver according to given coefficients
Parameters:
Name Type Argument Description
coeffs Array.<number> | JSMatrix.Vector coefficients of permutation. The content will be changed(!), use a copy if you need to preserve the content
backward boolean <optional>
=false] if false, receiver is permutated to given coefficients (forward). If true, from given coefficients (backward)
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1105
Returns:
permutated copy of receiver
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([7,9,6]);
v2 = v1.elementsPermutation([1,2,0]); // v2 = Vector([9,6,7])
v3 = v1.elementsPermutation([1,2,0],true); // v3 = Vector([6,7,9])

empty()

Empties receiver (resizes it to size 0)
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 138
Example
v = JSMatrix.vec([1,2,3,4]);
v.empty(); // v = Vector([])

energyNorm(mat) → {number}

Returns energy norm of receiver (ret = sqrt(this*mat*this))
Parameters:
Name Type Description
mat JSMatrix.Matrix marix of norm
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 559
Returns:
energy norm of receiver
Type
number
Example
v = JSMatrix.vec([1,2,3]);
m = JSMatrix.mat([[8,0,0],[0,2,1],[0,1,3]]);
n = v.energyNorm(m); // n = 7.4162

fromArray(arry)

Sets elements of receiver form given Array object
Parameters:
Name Type Description
arry Array.<number> Array object containing new receiver elements
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 362
Example
v.fromArray([3,6,5,2]); // v = Vector([3,6,5,2])

get(e) → {number|null}

Coefficient access function, returns one element of receiver ( ret = this[r] ). Vector.get(e) is almost equivalent to direct Vector[e] access method
Parameters:
Name Type Description
e number index of element to be returned
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 285
Returns:
value of the e-th element
Type
number | null
Example
v = JSMatrix.vec([4,7,2,4]);
a = v.get(1); // a = 7
a = v[1]; // a = 7
a = v.get(9); // a = null
a = v[9]; // a = undefined

getSubVector(coeffs) → {JSMatrix.Vector}

Returns subvector of receiver. ret = this[coeffs]
Parameters:
Name Type Description
coeffs Array.<number> | JSMatrix.Vector array containing coefficients of desired subvector
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 797
Returns:
desired subvector
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([4,7,9,1,8,3,2,4,6,7,5,1,6,9]);
v2 = v1.getSubVector([2,3,6,8,9]); // v2 = Vector([9,1,2,6,7])

getsv()

Alias for getSubVector, see JSMatrix.Vector#getSubVector
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 814

iadd(vec)

Add given vector to receiver ( this += vec )
Parameters:
Name Type Description
vec JSMatrix.Vector vector to be added
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 405
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([6,1,5]);
v1.iadd(v2); // v1 = Vector([7,3,8])

imulf(f)

Multiply receiver by float f ( this *= f )
Parameters:
Name Type Description
f number float multiplier
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 694
Example
v = JSMatrix.vec([1,2,3]);
v.imulf(3); // v = Vector([3,6,9])

incr(e, val)

Coefficient access function, increment one element of receiver ( this[r] += val ). Vector.incr(e,val) is much safer than direct Vector[e] += val (see example)
Parameters:
Name Type Description
e number index of element to be incremented
val number value to be added
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 319
Example
v = JSMatrix.vec([4,7,2,4]);
v.incr(1,4.); // v = Vector([4,11,2,4])
v[1] += 4.; // v = Vector([4,15,2,4])
v.incr(9,4.); // nothing is done, out of bounds
// v = Vector([4,15,2,4])
/// v[9] += 4. would result into error (v[9] is not defined)

incrSubVector(coeffs, vec)

Increment subvector at defined positions of receiver (this[coeffs] += vec)
Parameters:
Name Type Description
coeffs Array.<number> | JSMatrix.Vector array containing coefficients to be incremented
vec JSMatrix.Vector vector to be added
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 863
Example
v = JSMatrix.vec([4,7,9,1,8,3,2,4,6,7,5,1,6,9]);
v.incrSubVector([2,3,6,8,9],JSMatrix.vec([1.1,2.2,3.3,4.4,5.5])); // v = Vector([4,7,10.1,3.2,8,3,5.3,4,10.4,12.5,5,1,6,9])

incrsv()

Alias for incrSubVector, see JSMatrix.Vector#incrSubVector
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 876

indexOf(val) → {number|null}

Returns index of first occurrence of given value
Parameters:
Name Type Description
val number value whose index will be returned
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 250
Returns:
index of first occurrence of val
Type
number | null
Example
v = JSMatrix.vec([5,6,1,2,6,8,6,2]);
i1 = v.indexOf(2); // i1 = 3
i2 = v.indexOf(6); // i2 = 1
i3 = v.indexOf(8); // i3 = 5

ineg()

Alias for neagete(), see JSMatrix.Vector#negate
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 658

isEmpty()

Tests if receiver is empty (has size 0)
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 150
Returns:
true if receiver is empty, false otherwise
Example
v = new JSMatrix.Vector(3);
b1 = v.isEmpty(); // b1 = false
v.empty();
b2 = v.isEmpty(); // b2 = true

isEqualTo(vec) → {boolean}

Testing vectors equality
Parameters:
Name Type Description
vec JSMatrix.Vector vector to be compared with receiver
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 267
Returns:
true if this==vec, false otherwise
Type
boolean
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([1,2,2.999999999]);
v3 = JSMatrix.vec([1,2,1]);
t1 = v1.isEqualTo(v2); // t1 = true
t2 = v1.isEqualTo(v3); // t2 = false

isSameSizeAs(vec) → {boolean}

Testing vectors size equality
Parameters:
Name Type Description
vec JSMatrix.Vector vector to be tested
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 334
Returns:
true if vec and receiver has same size, false otherwise
Type
boolean
Example
a = JSMatrix.vec([1,2,3,4]);
b = JSMatrix.vec([5,6,7,8,9,10,11,12]);
c = JSMatrix.vec([13,14,15,16]);
t1 = a.isSameSizeAs(b); // t1 = false
t2 = a.isSameSizeAs(c); // t2 = true

isub(vec)

Subtract given vector to receiver ( this -= vec )
Parameters:
Name Type Description
vec JSMatrix.Vector vector to be subtracted
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 449
Example
v1 = JSMatrix.vec([1,2,3]);
v1.isub(v2); // v1 = Vector([-5,1,-2])

max() → {number}

Returns maximal value of receiver elements
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 205
Returns:
maximal value of receiver elements
Type
number
Example
v = JSMatrix.vec([1,-4,3,2]);
m = v.max(); // m = 3

min() → {number}

Returns minimal value of receiver elements
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 219
Returns:
minimal value of receiver elements
Type
number
Example
v = JSMatrix.vec([1,-4,3,2]);
m = v.min(); // m = -4

mul(what) → {JSMatrix.Vector}

Returns product of receiver and given multiplier (float or Matrix)
Parameters:
Name Type Description
what JSMatrix.Matrix | number matrix or float to multiply
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 728
Returns:
copy of receiver multiplied by what
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = v1.mul(JSMatrix.mat([[11,12,13],[21,22,23],[31,32,33]])); // v2 = Vector([146,152,158])
v3 = v1.mul(3); // v3 = Vector([3,6,9])

mulf(f) → {JSMatrix.Vector}

Returns receiver multiplied by float f ( ret = this * f )
Parameters:
Name Type Description
f number float multiplier
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 681
Returns:
copy of receiver multiplied by f
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = v1.mulf(3); // v2 = Vector([3,6,9])

mulm(mat) → {JSMatrix.Vector}

Returns product of receiver and given matrix ( ret = this^T * mat )
Parameters:
Name Type Description
mat JSMatrix.Matrix matrix to multiply
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 706
Returns:
copy of receiver multiplied by mat
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([1,2,3]);
m = JSMatrix.mat([[11,12,13],[21,22,23],[31,32,33]])
v2 = v1.mulm(m); // v2 = Vector([146,152,158])

neg()

Alias for negated(), see JSMatrix.Vector#negated
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 644

negate()

Negate receiver ( ret *= -1., ret = -ret )
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 651
Example
v1 = JSMatrix.vec([1,2,3]);
v1.negate(); // v1 = Vector([-1,-2,-3])

negated() → {JSMatrix.Vector}

Returns negative of receiver ( ret = -this )
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 637
Returns:
negative of receiver
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = v1.negated(); // v2 = Vector([-1,-2,-3])

norm() → {number}

Returns (Euclidean) norm of receiver (ret = sqrt(this^T * this) )
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 509
Returns:
Euclidean norm of receiver
Type
number
Example
v = JSMatrix.vec([4,2,4]);
n = v.norm(); // n = 6

normalize()

Normlize receiver ( this.norm()=1. )
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 518
Example
v = JSMatrix.vec([4,2,4]);
v.normalize(); // v = Vector([0.6666,0.3333,0.6666])

normalized() → {JSMatrix.Vector}

Returns normalized copy of receiver ( ret.norm()=1. )
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 530
Returns:
normalized copy of receiver
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([4,2,4]);
v2 = v1.normalized(); // v2 = Vector([0.6666,0.3333,0.6666])

one()

Alias for beFullOfOnes(), see JSMatrix.Vector#beFullOfOnes
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 175

otimes()

Alias for dyadic() (inspired by LaTeX symbol for dyadic product operation), see JSMatrix.Vector#dyadic
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 585

outer()

Alias for dyadic(), see JSMatrix.Vector#dyadic
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 590

permuteElements(coeffs, backward)

Permute elements of receiver according to given coefficients
Parameters:
Name Type Argument Description
coeffs Array.<number> | JSMatrix.Vector coefficients of permutation
backward boolean <optional>
=false] if false, receiver is permutated to given coefficients (forward). If true, from given coefficients (backward)
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1063
Example
v = JSMatrix.vec([7,9,6]);
v.permuteElements([1,2,0]); // v = Vector([9,6,7])
v.permuteElements([1,2,0],true); // v = Vector([7,9,6])

resize(nElements)

Resize receiver according to given size (delete extra elements or add zero elements)
Parameters:
Name Type Description
nElements number new number of elements
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1131
Example
v1 = JSMatrix.vec([4,7,9,1,7,3])
v2 = JSMatrix.vec([4,6]);
v1.resize(4); // v1 = Vector([4,7,9,1])
v2.resize(4); // v2 = Vector([4,6,0,0])

resized(nElements) → {JSMatrix.Vector}

Returns resized copy of receiver according to given size (delete extra elements or add zero elements)
Parameters:
Name Type Description
nElements number new number of elements
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1153
Returns:
resized copy of receiver
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([4,7,9,1]);
v2 = v1.resized(2); // v2 = Vector([4,7])
v3 = v1.resized(6); // v3 = Vector([4,7,9,1,0,0])

set(e, val)

Coefficient access function, sets one element of receiver ( this[r] = val ). Vector.set(e) is almost equivalent to direct Vector[e] access method
Parameters:
Name Type Description
e number index of element to be set
val number value to be set
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 303
Example
v = JSMatrix.vec([4,7,2,4]);
v.set(1,68.); // v = Vector([4,68,2,4])
v[1] = 43.; // v = Vector([4,43,2,4])
v.set(9,68.); // nothing is done - out of bounds
// v = Vector([4,43,2,4])
v[9] = 43.;
/// new object this[9] is created, but no reflection to actual Vector is made
// v = Vector([4,43,2,4])

setSubVector(coeffs, vec)

Sets subvector at defined positions of receiver ( this[coeffs]=vec )
Parameters:
Name Type Description
coeffs Array.<number> | JSMatrix.Vector array containing coefficients to be set
vec JSMatrix.Vector vector to be set
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 841
Example
v = JSMatrix.vec([4,7,9,1,8,3,2,4,6,7,5,1,6,9]);
v.setSubVector([2,3,6,8,9],JSMatrix.vec([1.1,2.2,3.3,4.4,5.5])); // v = Vector([4,7,1.1,2.2,8,3,3.3,4,4.4,5.5,5,1,6,9])

setsv()

Alias for setSubVector, see JSMatrix.Vector#setSubVector
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 854

size() → {number}

Returns size (numer of elements) of receiver
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 183
Returns:
length (number of elements) of receiver
Type
number
Example
v = JSMatrix.vec([1,5,8,2]);
s = v.size(); // s = 4

squaredEnergyNorm(mat) → {number|null}

Returns squared energy norm of receiver (ret = this^T*mat*this)
Parameters:
Name Type Description
mat JSMatrix.Matrix marix of norm
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 547
Returns:
squared energy norm of receiver
Type
number | null
Example
v = JSMatrix.vec([1,2,3]);
m = JSMatrix.mat([[8,0,0],[0,2,1],[0,1,3]]);
n = v.squaredEnergyNorm(m); // n = 55

squaredNorm() → {number}

Returns squared (Euclidean) norm of receiver (ret = this.^T * this )
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 495
Returns:
squared Euclidean norm of receiver
Type
number
Example
v = JSMatrix.vec([4,2,4]);
n = v.squaredNorm(); // n = 36

sub(vec) → {JSMatrix.Vector}

Returns difference of receiver and vector ( ret = this - vec )
Parameters:
Name Type Description
vec JSMatrix.Vector 2nd vector of subtraction
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 435
Returns:
difference of receiver and vec
Type
JSMatrix.Vector
Example
v1 = JSMatrix.vec([1,2,3]);
v2 = JSMatrix.vec([6,1,5]);
v4 = v1.sub(v2); // v4 = Vector([-5,1,-2])

sum() → {number}

Returns sum of all elements of receiver
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 193
Returns:
sum of all elements of receiver
Type
number
Example
v = JSMatrix.vec([1,2,3]);
s = v.sum(); // s = 6

swapElements(e1, e2)

Swaps two elements of receiver
Parameters:
Name Type Description
e1 number index of first element to swap
e2 number index of second element to swap
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1016
Example
v = JSMatrix.vec([1,2,3,4,5,6,7]);
v.swapElements(1,4); // v = Vector([1,5,3,4,2,6,7])

tensor()

Alias for dyadic(), see JSMatrix.Vector#dyadic
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 595

toArray() → {Array.<number>}

Returns elements of receiver as an Array object
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 376
Returns:
Array object containing receiver's elements
Type
Array.<number>
Example
v = JSMatrix.vec([3,4,5,6]);
s = v.toArray(); // s = [3,4,5,6]

toDiagonalMatrix() → {JSMatrix.Matrix}

Returns matrix with receiver's elements on its diagonal
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 1171
Returns:
diagonal matrix with receiver's elements on its diagonal
Type
JSMatrix.Matrix
Example
v = JSMatrix.vec([1,2,3]);
m = v.toDiagonalMatrix(); // m = Matrix([[1,0,0],[0,2,0],[0,0,3]])

toString() → {string}

Returns string representation of receiver
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 996
Returns:
string representation of receiver
Type
string
Example
v1 = JSMatrix.vec([0.5999999999999999,2,3]);
s = v1.toString(); // s = 'Vector([ 1, 2, 3 ])'

x()

Alias for mul(), see JSMatrix.Vector#mul
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 738

zero()

Zeroes all elements of receiver
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 159
Example
v = JSMatrix.vec([1,2,3,4]);
v.zero(); // v = Vector([0,0,0,0])