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
this
with itself.Examples
Vector.create(3, 4).sizesq; // 25
Details
-
size :number
The geometric length of the vector.
-
Description
This is the square root of
this.sizesq
.Examples
Vector.create(3, 4).size; // 5
Details
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 entries
number <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
n
entries equal toc
. -
Parameters
Name Type Description n
integer The size of the resulting Vector.
c
number 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
n
entries equal to zero. -
Parameters
Name Type Description n
integer 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
i
th equal to 1.Parameters
Name Type Attributes Default Description i
integer The nonzero entry.
n
integer 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 = 0
has only the solutionc1 = c2 = ... = cn = 0
. Equivalently, the matrix with columnsv1, v2, ..., vn
has full column rank.Parameters
Name Type Attributes Default Description vecs
Array.<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)]); // false
Throws
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 vecs
Array.<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)]); // true
Throws
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 vecs
Array.<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, ..., vn
with coefficientsc1, c2, ..., cn
is the vectorc1 v1 + c2 v2 + ... + cn vn
.Parameters
Name Type Description coeffs
Array.<number> A non-empty array of coefficients.
vecs
Array.<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 other
Vector 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)); // false
Details
-
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 precision
integer <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 precision
integer <optional> 4 The number of decimal places to include.
opts
Object <optional> {} Options.
Name Type Attributes Default Description env
string <optional> "bmatrix" The matrix environment to use.
row
boolean <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 entries
number <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 other
Vector The vector to add.
factor
number <optional> 1 Add
factor
timesother
instead of just addingother
.start
integer <optional> 0 Only add the entries
start...this.length
. Provided for optimizations when the entries ofother
beforestart
are 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 other
Vector The vector to subtract.
start
integer <optional> 0 Only subtract the entries
start...this.length
. Provided for optimizations when the entries ofother
beforestart
are 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 c
number The scaling factor.
start
integer <optional> 0 Only scale the entries
start...this.length
. Provided for optimizations when the entries beforestart
are 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
this
andother
.Parameters
Name Type Description other
Vector The vector to dot.
Returns
Examples
let v = Vector.create(1, 2), w = Vector.create(3, 4); v.dot(w); // 1*3 + 2*4
Throws
Details