Members
-
sizesq :number
The square of the geometric length of the vector.
-
Description
This is the sum of the squares of the entries, which is the dot product of
thiswith itself.Examples
Vector.create(3, 4).sizesq; // 25Details
-
size :number
The geometric length of the vector.
-
Description
This is the square root of
this.sizesq.Examples
Vector.create(3, 4).size; // 5Details
Methods
-
<static> create( ...entries ) → {Vector}
Create a Vector with the given entries.
-
Description
This is an alias for
Vector.of.Parameters
Name Type Attributes Description entriesnumber <repeatable> The entries of the resulting Vector.
Returns
Examples
Vector.create(1).toString(1); // "[1.0]" Vector.create(1, 2).toString(1); // "[1.0 2.0]"Details
-
<static> constant( n, c ) → {Vector}
Create a Vector with
nentries equal toc. -
Parameters
Name Type Description ninteger The size of the resulting Vector.
cnumber The value of the entries.
Returns
Examples
Vector.constant(3, 1).toString(1); // "[1.0 1.0 1.0]"Details
-
<static> zero( n ) → {Vector}
Create a Vector with
nentries equal to zero. -
Parameters
Name Type Description ninteger The size of the resulting Vector.
Returns
Examples
Vector.zero(3).toString(1); // "[0.0 0.0 0.0]"Details
-
<static> e( i, n [, λ ] ) → {Vector}
Create a unit coordinate vector.
-
Description
This is the Vector with all entries equal to 0, except the
ith equal to 1.Parameters
Name Type Attributes Default Description iinteger The nonzero entry.
ninteger The size of the resulting Vector.
λnumber <optional> 1 The nonzero entry is set to this.
Returns
Examples
Vector.e(1, 3).toString(1); // "[0.0 1.0 0.0]"Details
-
<static> isLinearlyIndependent( vecs [, ε ] ) → {boolean}
Check if an iterable of vectors is linearly independent.
-
Description
This means that the vector equation
c1 v1 + c2 v2 + ... + cn vn = 0has only the solutionc1 = c2 = ... = cn = 0. Equivalently, the matrix with columnsv1, v2, ..., vnhas full column rank.Parameters
Name Type Attributes Default Description vecsArray.<Vector> The vectors to check.
εnumber <optional> 1e-10 Entries smaller than this value are taken to be zero for the purposes of pivoting.
Returns
Examples
Vector.isLinearlyIndependent( [Vector.create(1, 0, 0), Vector.create(0, 1, 0), Vector.create(0, 0, 1)]); // true Vector.isLinearlyIndependent( [Vector.create(1, 0, 0), Vector.create(0, 1, 0), Vector.create(1, 1, 0)]); // falseThrows
Details
-
<static> isLinearlyDependent( vecs [, ε ] ) → {boolean}
Check if an iterable of vectors is linearly dependent.
-
Description
This is an alias for
!Vector.isLinearlyIndependent(vecs).Parameters
Name Type Attributes Default Description vecsArray.<Vector> The vectors to check.
εnumber <optional> 1e-10 Entries smaller than this value are taken to be zero for the purposes of pivoting.
Returns
Examples
Vector.isLinearlyDependent( [Vector.create(1, 0, 0), Vector.create(0, 1, 0), Vector.create(0, 0, 1)]); // false Vector.isLinearlyDependent( [Vector.create(1, 0, 0), Vector.create(0, 1, 0), Vector.create(1, 1, 0)]); // trueThrows
Details
-
<static> linearlyIndependentSubset( vecs [, ε ] ) → {Array.<Vector>}
Return a linearly independent subset.
-
Description
This returns an Array containing a maximal linearly independent subset of vectors from
vecs.Parameters
Name Type Attributes Default Description vecsArray.<Vector> The vectors to use.
εnumber <optional> 1e-10 Entries smaller than this value are taken to be zero for the purposes of pivoting.
Returns
Examples
let v1 = Vector.create(1, 0, 0); let v2 = Vector.create(0, 1, 0); let v3 = Vector.create(1, 1, 0); Vector.linearlyIndependentSubset([v1, v2, v3]); // [v1, v2]Throws
Details
-
<static> linearCombination( coeffs, vecs )
Compute a linear combination of vectors.
-
Description
The linear combination of the vectors
v1, v2, ..., vnwith coefficientsc1, c2, ..., cnis the vectorc1 v1 + c2 v2 + ... + cn vn.Parameters
Name Type Description coeffsArray.<number> A non-empty array of coefficients.
vecsArray.<Vector> A non-empty array of vectors, of the same length as
coeffs.Returns
Examples
let v1 = Vector.create(1, 0, 0); let v2 = Vector.create(0, 1, 0); let v3 = Vector.create(1, 1, 0); Vector.linearCombination([1, 2, 3], [v1, v2, v3]).toString(1); // "[4.0 5.0 0.0]"Throws
Details
-
equals( other [, ε ] ) → {boolean}
Check if this vector is equal to
other. -
Description
Two vectors are equal if they have the same number of entries, and all entries are equal.
Parameters
Name Type Attributes Default Description otherVector The vector to compare.
εnumber <optional> 0 Entries will test as equal if they are within
εof each other. This is provided in order to account for rounding errors.Returns
Examples
let v = Vector.create(0.01, -0.01, 0); let w = Vector.zero(3); v.equals(w); // false v.equals(w, 0.05); // true w.equals(Vector.zero(2)); // falseDetails
-
clone() → {Vector}
Create a new Vector with the same entries.
-
Returns
Details
-
toString( [ precision ] ) → {string}
Return a string representation of the vector.
-
Parameters
Name Type Attributes Default Description precisioninteger <optional> 4 The number of decimal places to include.
Returns
Examples
Vector.create(1, 2, 3).toString(2); // "[1.00 2.00 3.00]"Details
-
toLaTeX( [ precision [, opts ] ] ) → {string}
Return a LaTeX representation of the vector.
-
Parameters
Name Type Attributes Default Description precisioninteger <optional> 4 The number of decimal places to include.
optsObject <optional> {} Options.
Name Type Attributes Default Description envstring <optional> "bmatrix" The matrix environment to use.
rowboolean <optional> false Print as a row vector instead of a column vector.
Returns
Examples
Vector.create(1, 2, 3).toLaTeX(2); // "\begin{bmatrix} 1.00 \\ 2.00 \\ 3.00 \end{bmatrix}"Details
-
isZero( [ ε ] ) → {boolean}
Decide if a vector is zero.
-
Description
This is functionally equivalent to
this.equals(Vector.zero(this.length), ε).Parameters
Name Type Attributes Default Description εnumber <optional> 0 Entries smaller than this in absolute value will be considered zero.
Returns
Details
-
normalize() → {Vector}
Scale the vector by the reciprocal of its length.
-
Description
This modifies the vector in-place to have size 1.
Returns
Examples
let v = Vector.create(3, 4); v.normalize(); v.toString(2); // "[0.60 0.80]"Throws
Details
-
set( ...entries ) → {Vector}
Set multiple components of a Vector.
-
Description
This modifies the vector by setting the components to the passed values.
Parameters
Name Type Attributes Description entriesnumber <repeatable> The new entries of the vector.
Returns
Examples
let v = Vector.zero(2); v.set(3, 4); v.toString(1); // "[3.0, 4.0]"Throws
Details
-
add( other [, factor [, start ] ] ) → {Vector}
Add a Vector in-place.
-
Description
This modifies the vector in-place by adding the entries of
other.Parameters
Name Type Attributes Default Description otherVector The vector to add.
factornumber <optional> 1 Add
factortimesotherinstead of just addingother.startinteger <optional> 0 Only add the entries
start...this.length. Provided for optimizations when the entries ofotherbeforestartare known to be zero.Returns
Examples
let v = Vector.create(1, 2), w = Vector.create(3, 4); v.add(w); v.toString(1); // "[4.0 6.0]"Throws
Details
-
sub( other [, start ] ) → {Vector}
Subtract a Vector in-place.
-
Description
This modifies the vector in-place by subtracting the entries of
other.Parameters
Name Type Attributes Default Description otherVector The vector to subtract.
startinteger <optional> 0 Only subtract the entries
start...this.length. Provided for optimizations when the entries ofotherbeforestartare known to be zero.Returns
Examples
let v = Vector.create(1, 2), w = Vector.create(3, 4); v.sub(w); v.toString(1); // "[-2.0 -2.0]"Throws
Details
-
scale( c [, start ] ) → {Vector}
Multiply a Vector by a scalar in-place.
-
Description
This modifies the vector in-place by multiplying all entries by
c.Parameters
Name Type Attributes Default Description cnumber The scaling factor.
startinteger <optional> 0 Only scale the entries
start...this.length. Provided for optimizations when the entries beforestartare known to be zero.Returns
Examples
let v = Vector.create(1, 2); v.scale(2); v.toString(1); // "[2.0 4.0]"Details
-
dot( other ) → {number}
Compute the dot product with another vector.
-
Description
This is the sum of the pairwise products of the entries of
thisandother.Parameters
Name Type Description otherVector The vector to dot.
Returns
Examples
let v = Vector.create(1, 2), w = Vector.create(3, 4); v.dot(w); // 1*3 + 2*4Throws
Details