Members
-
<static> i :Complex
A copy of
i = new Complex(0, 1)
, a square root of -1. -
Description
This returns a new object each time it is accessed.
Details
-
Re :number
The real part (first entry) of the complex number.
-
Examples
let z = new Complex(3, 4); z.Re; // 3 z.Re = 5; z.toString(1); // "5.0 + 4.0 i"
Details
-
Im :number
The imaginary part part (second entry) of the complex number.
-
Examples
let z = new Complex(3, 4); z.Im; // 4 z.Im = 5; z.toString(1); // "3.0 + 5.0 i"
Details
-
mod :number
The modulus of the complex number.
-
Description
This is an alias for the inherited property
this.size
.Examples
new Complex(3, 4).mod; // 5
Details
-
arg :number
The argument of the complex number.
-
Description
This is the angle component of the polar coordinates for the point
(this.Re, this.Im)
.The value is between -π and π.
Examples
new Complex(1, 1).arg; // Math.PI/4
Details
-
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> fromPolar( r, θ ) → {Complex}
Create a new Complex number with prescribed polar coordinates.
-
Description
Cartesian and polar coordinates are related by the formula
(x, y) = (r cos(θ), r sin(θ))
. According to Euler's formula, the output ofComplex.fromPolar(r, θ)
is equal tor e^{i θ}
.Parameters
Name Type Description r
number The radial coordinate.
θ
number The angular coordinate.
Returns
Examples
Complex.fromPolar(1, Math.PI/2); // Complex.i
Details
-
equals( other [, ε ] ) → {boolean}
Test if this complex number is equal to
other
. -
Description
This is the same as Vector#equals, except that if
other
is a number, it is promoted to a Complex number first.Parameters
Name Type Attributes Default Description other
Complex | number The number 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
new Complex(1, 0).equals(1); // true
Details
-
toString( [ precision ] ) → {string}
Return a string representation of the complex number.
-
Parameters
Name Type Attributes Default Description precision
integer <optional> 4 The number of decimal places to include.
Returns
Examples
new Complex(1, 2).toString(2); // "1.00 + 2.00 i"
Details
-
conj() → {Complex}
Replace the Complex number with its complex conjugate.
-
Description
This modifies
this
in place by negating the imaginary part.Returns
Examples
let z = new Complex(1, 2); z.conj(); z.toString(1); // "1.0 - 2.0 i"
Details
-
add( other [, factor ] ) → {Complex}
Add another complex number in-place.
-
Description
This is the same as Vector#add, except that if
other
is a number, it is promoted to a Complex number first.Parameters
Name Type Attributes Default Description other
Complex | number The number to add.
factor
number <optional> 1 Add
factor
timesother
instead of just addingother
.Returns
Examples
let z = new Complex(1, 2); z.add(1); z.toString(1); // "2.0 + 2.0 i"
Details
-
mult( other ) → {Complex}
Multiply by a complex number in-place.
-
Description
Multiplication of complex numbers is defined by the formula
(a + b i) (c + d i) = (ac - bd) + (ad + bc) i
.Parameters
Name Type Description other
Complex | number The number to multiply.
Returns
Examples
let z = new Complex(1, 2), w = new Complex(3, 4); z.mult(w); z.toString(1); // "-5.0 + 10.0 i" z.mult(-2); z.toString(1); // "10.0 - 20.0 i"
Details
-
pow( x ) → {Complex}
Raise to the power
x
. -
Description
This returns a new Complex number whose modulus is
this.mod
raised to the powerx
and whose argument isx*this.arg
.Parameters
Name Type Description x
number The exponent.
Returns
Examples
new Complex( 1, 2).pow(2 ).toString(1); // "-3.0 + 4.0 i" new Complex(-3, 4).pow(1/2).toString(1); // "1.0 + 2.0 i"
Details
-
clone() → {Vector}
Create a new Vector with the same entries.
-
Returns
Details
-
recip() → {Complex}
Replace the Complex number by its reciprocal.
-
Description
The reciprocal of a nonzero complex number
a + b i
is(a - b i)/(a^2 + b^2)
.Returns
Examples
let z = new Complex(3, 4); z.recip(); z.toString(); // "0.1200 - 0.1600 i"
Throws
Details
-
div( other ) → {Complex}
Divide by a complex number in-place.
-
Description
This is the same as
this.mult(other.recip())
, exceptother
is not modified.Parameters
Name Type Description other
Complex | number The number to divide.
Returns
Examples
let z = new Complex(1, 2), w = new Complex(3, 4); z.div(w); z.toString(); // "0.440 + 0.0800 i"
Throws
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
-
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