|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.math3.complex.Complex
public class Complex
Representation of a Complex number, i.e. a number which has both a
real and imaginary part.
Implementations of arithmetic operations handle NaN and
infinite values according to the rules for Double, i.e.
equals(java.lang.Object) is an equivalence relation for all instances that have
a NaN in either real or imaginary part, e.g. the following are
considered equal:
1 + NaNiNaN + iNaN + NaNix == x must fail if
x is NaN). The method
equals for primitive double in Precision
conforms with IEEE-754 while this class conforms with the standard behavior
for Java object types.
| Field Summary | |
|---|---|
static Complex |
I
The square root of -1. |
static Complex |
INF
A complex number representing "+INF + INFi" |
static Complex |
NaN
A complex number representing "NaN + NaNi" |
static Complex |
ONE
A complex number representing "1.0 + 0.0i" |
static Complex |
ZERO
A complex number representing "0.0 + 0.0i" |
| Constructor Summary | |
|---|---|
Complex(double real)
Create a complex number given only the real part. |
|
Complex(double real,
double imaginary)
Create a complex number given the real and imaginary parts. |
|
| Method Summary | |
|---|---|
double |
abs()
Return the absolute value of this complex number. |
Complex |
acos()
Compute the inverse cosine of this complex number. |
Complex |
add(Complex addend)
Returns a Complex whose value is
(this + addend). |
Complex |
add(double addend)
Returns a Complex whose value is (this + addend),
with addend interpreted as a real number. |
Complex |
asin()
Compute the inverse sine of this complex number. |
Complex |
atan()
Compute the inverse tangent of this complex number. |
Complex |
conjugate()
Return the conjugate of this complex number. |
Complex |
cos()
Compute the cosine of this complex number. |
Complex |
cosh()
Compute the hyperbolic cosine of this complex number. |
protected Complex |
createComplex(double realPart,
double imaginaryPart)
Create a complex number given the real and imaginary parts. |
Complex |
divide(Complex divisor)
Returns a Complex whose value is
(this / divisor). |
Complex |
divide(double divisor)
Returns a Complex whose value is (this / divisor),
with divisor interpreted as a real number. |
boolean |
equals(Object other)
Test for the equality of two Complex objects. |
Complex |
exp()
Compute the exponential function of this complex number. |
double |
getArgument()
Compute the argument of this complex number. |
ComplexField |
getField()
Get the Field to which the instance belongs. |
double |
getImaginary()
Access the imaginary part. |
double |
getReal()
Access the real part. |
int |
hashCode()
Get a hashCode for the complex number. |
boolean |
isInfinite()
Checks whether either the real or imaginary part of this complex number takes an infinite value (either Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITY) and neither part
is NaN. |
boolean |
isNaN()
Checks whether either or both parts of this complex number is NaN. |
Complex |
log()
Compute the natural logarithm of this complex number. |
Complex |
multiply(Complex factor)
Returns a Complex whose value is this * factor. |
Complex |
multiply(double factor)
Returns a Complex whose value is this * factor, with factor
interpreted as a real number. |
Complex |
multiply(int factor)
Returns a Complex whose value is this * factor, with factor
interpreted as a integer number. |
Complex |
negate()
Returns a Complex whose value is (-this). |
List<Complex> |
nthRoot(int n)
Computes the n-th roots of this complex number. |
Complex |
pow(Complex x)
Returns of value of this complex number raised to the power of x. |
Complex |
pow(double x)
Returns of value of this complex number raised to the power of x. |
protected Object |
readResolve()
Resolve the transient fields in a deserialized Complex Object. |
Complex |
reciprocal()
Returns the multiplicative inverse of this element. |
Complex |
sin()
Compute the sine of this complex number. |
Complex |
sinh()
Compute the hyperbolic sine of this complex number. |
Complex |
sqrt()
Compute the square root of this complex number. |
Complex |
sqrt1z()
Compute the square root of 1 - this2 for this complex
number. |
Complex |
subtract(Complex subtrahend)
Returns a Complex whose value is
(this - subtrahend). |
Complex |
subtract(double subtrahend)
Returns a Complex whose value is
(this - subtrahend). |
Complex |
tan()
Compute the tangent of this complex number. |
Complex |
tanh()
Compute the hyperbolic tangent of this complex number. |
String |
toString()
|
static Complex |
valueOf(double realPart)
Create a complex number given only the real part. |
static Complex |
valueOf(double realPart,
double imaginaryPart)
Create a complex number given the real and imaginary parts. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Complex I
public static final Complex NaN
public static final Complex INF
public static final Complex ONE
public static final Complex ZERO
| Constructor Detail |
|---|
public Complex(double real)
real - Real part.
public Complex(double real,
double imaginary)
real - Real part.imaginary - Imaginary part.| Method Detail |
|---|
public double abs()
NaN if either real or imaginary part is NaN
and Double.POSITIVE_INFINITY if neither part is NaN,
but at least one part is infinite.
public Complex add(Complex addend)
throws NullArgumentException
Complex whose value is
(this + addend).
Uses the definitional formula
(a + bi) + (c + di) = (a+c) + (b+d)i
this or addend has a NaN value in
either part, NaN is returned; otherwise Infinite
and NaN values are returned in the parts of the result
according to the rules for Double arithmetic.
add in interface FieldElement<Complex>addend - Value to be added to this Complex.
this + addend.
NullArgumentException - if addend is null.public Complex add(double addend)
Complex whose value is (this + addend),
with addend interpreted as a real number.
addend - Value to be added to this Complex.
this + addend.add(Complex)public Complex conjugate()
a + bi is a - bi.
NaN is returned if either the real or imaginary
part of this Complex number equals Double.NaN.
NaN, the returned value has infinite imaginary part
of the opposite sign, e.g. the conjugate of
1 + POSITIVE_INFINITY i is 1 - NEGATIVE_INFINITY i.
public Complex divide(Complex divisor)
throws NullArgumentException
Complex whose value is
(this / divisor).
Implements the definitional formula
a + bi ac + bd + (bc - ad)i
----------- = -------------------------
c + di c2 + d2
but uses
prescaling of operands to limit the effects of overflows and
underflows in the computation.
Infinite and NaN values are handled according to the
following rules, applied in the order presented:
this or divisor has a NaN value
in either part, NaN is returned.
divisor equals ZERO, NaN is returned.
this and divisor are both infinite,
NaN is returned.
this is finite (i.e., has no Infinite or
NaN parts) and divisor is infinite (one or both parts
infinite), ZERO is returned.
this is infinite and divisor is finite,
NaN values are returned in the parts of the result if the
Double rules applied to the definitional formula
force NaN results.
divide in interface FieldElement<Complex>divisor - Value by which this Complex is to be divided.
this / divisor.
NullArgumentException - if divisor is null.public Complex divide(double divisor)
Complex whose value is (this / divisor),
with divisor interpreted as a real number.
divisor - Value by which this Complex is to be divided.
this / divisor.divide(Complex)public Complex reciprocal()
this element.
reciprocal in interface FieldElement<Complex>this.public boolean equals(Object other)
Double.NaN, the two
Complex objects are considered to be equal.
All NaN values are considered to be equal - i.e, if either
(or both) real and imaginary parts of the complex number are equal
to Double.NaN, the complex number is equal to
NaN.
equals in class Objectother - Object to test for equality to this
null, not an instance of Complex, or not equal to this Complex
instance.public int hashCode()
Double.NaN value in real or imaginary part produces
the same hash code 7.
hashCode in class Objectpublic double getImaginary()
public double getReal()
public boolean isNaN()
NaN.
NaN; false otherwise.public boolean isInfinite()
Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITY) and neither part
is NaN.
NaN.
public Complex multiply(Complex factor)
throws NullArgumentException
Complex whose value is this * factor.
Implements preliminary checks for NaN and infinity followed by
the definitional formula:
(a + bi)(c + di) = (ac - bd) + (ad + bc)i
Returns NaN if either this or factor has one or
more NaN parts.
INF if neither this nor factor has one
or more NaN parts and if either this or factor
has one or more infinite parts (same result is returned regardless of
the sign of the components).
multiply in interface FieldElement<Complex>factor - value to be multiplied by this Complex.
this * factor.
NullArgumentException - if factor is null.public Complex multiply(int factor)
Complex whose value is this * factor, with factor
interpreted as a integer number.
multiply in interface FieldElement<Complex>factor - value to be multiplied by this Complex.
this * factor.multiply(Complex)public Complex multiply(double factor)
Complex whose value is this * factor, with factor
interpreted as a real number.
factor - value to be multiplied by this Complex.
this * factor.multiply(Complex)public Complex negate()
Complex whose value is (-this).
Returns NaN if either real or imaginary
part of this Complex number equals Double.NaN.
negate in interface FieldElement<Complex>-this.
public Complex subtract(Complex subtrahend)
throws NullArgumentException
Complex whose value is
(this - subtrahend).
Uses the definitional formula
(a + bi) - (c + di) = (a-c) + (b-d)i
If either this or subtrahend has a NaN] value in either part,
NaN is returned; otherwise infinite and NaN values are
returned in the parts of the result according to the rules for
Double arithmetic.
subtract in interface FieldElement<Complex>subtrahend - value to be subtracted from this Complex.
this - subtrahend.
NullArgumentException - if subtrahend is null.public Complex subtract(double subtrahend)
Complex whose value is
(this - subtrahend).
subtrahend - value to be subtracted from this Complex.
this - subtrahend.subtract(Complex)public Complex acos()
acos(z) = -i (log(z + i (sqrt(1 - z2))))
Returns NaN if either real or imaginary part of the
input argument is NaN or infinite.
public Complex asin()
asin(z) = -i (log(sqrt(1 - z2) + iz))
Returns NaN if either real or imaginary part of the
input argument is NaN or infinite.
public Complex atan()
atan(z) = (i/2) log((i + z)/(i - z))
Returns NaN if either real or imaginary part of the
input argument is NaN or infinite.
public Complex cos()
cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i
where the (real) functions on the right-hand side are
Math.sin(double), Math.cos(double),
FastMath.cosh(double) and FastMath.sinh(double).
NaN if either real or imaginary part of the
input argument is NaN.
Examples:
cos(1 ± INFINITY i) = 1 ∓ INFINITY i
cos(±INFINITY + i) = NaN + NaN i
cos(±INFINITY ± INFINITY i) = NaN + NaN i
public Complex cosh()
cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)i}
where the (real) functions on the right-hand side are
Math.sin(double), Math.cos(double),
FastMath.cosh(double) and FastMath.sinh(double).
NaN if either real or imaginary part of the
input argument is NaN.
Examples:
cosh(1 ± INFINITY i) = NaN + NaN i
cosh(±INFINITY + i) = INFINITY ± INFINITY i
cosh(±INFINITY ± INFINITY i) = NaN + NaN i
public Complex exp()
exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i
where the (real) functions on the right-hand side are
Math.exp(double), Math.cos(double), and
Math.sin(double).
NaN if either real or imaginary part of the
input argument is NaN.
Examples:
exp(1 ± INFINITY i) = NaN + NaN i
exp(INFINITY + i) = INFINITY + INFINITY i
exp(-INFINITY + i) = 0 + 0i
exp(±INFINITY ± INFINITY i) = NaN + NaN i
ethis.public Complex log()
log(a + bi) = ln(|a + bi|) + arg(a + bi)i
where ln on the right hand side is Math.log(double),
|a + bi| is the modulus, abs(), and
arg(a + bi) = Math.atan2(double, double)(b, a).
NaN if either real or imaginary part of the
input argument is NaN.
Examples:
log(1 ± INFINITY i) = INFINITY ± (π/2)i
log(INFINITY + i) = INFINITY + 0i
log(-INFINITY + i) = INFINITY + πi
log(INFINITY ± INFINITY i) = INFINITY ± (π/4)i
log(-INFINITY ± INFINITY i) = INFINITY ± (3π/4)i
log(0 + 0i) = -INFINITY + 0i
ln this, the natural logarithm
of this.
public Complex pow(Complex x)
throws NullArgumentException
x.
Implements the formula:
yx = exp(x·log(y))
where exp and log are exp() and
log(), respectively.
NaN if either real or imaginary part of the
input argument is NaN or infinite, or if y
equals ZERO.
x - exponent to which this Complex is to be raised.
thisx.
NullArgumentException - if x is null.public Complex pow(double x)
x.
x - exponent to which this Complex is to be raised.
thisx.pow(Complex)public Complex sin()
sin(a + bi) = sin(a)cosh(b) - cos(a)sinh(b)i
where the (real) functions on the right-hand side are
Math.sin(double), Math.cos(double),
FastMath.cosh(double) and FastMath.sinh(double).
NaN if either real or imaginary part of the
input argument is NaN.
NaN values returned in parts of the result.
Examples:
sin(1 ± INFINITY i) = 1 ± INFINITY i
sin(±INFINITY + i) = NaN + NaN i
sin(±INFINITY ± INFINITY i) = NaN + NaN i
public Complex sinh()
sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)i
where the (real) functions on the right-hand side are
Math.sin(double), Math.cos(double),
FastMath.cosh(double) and FastMath.sinh(double).
NaN if either real or imaginary part of the
input argument is NaN.
Examples:
sinh(1 ± INFINITY i) = NaN + NaN i
sinh(±INFINITY + i) = ± INFINITY + INFINITY i
sinh(±INFINITY ± INFINITY i) = NaN + NaN i
this.public Complex sqrt()
sqrt(a + bi):
t = sqrt((|a| + |a + bi|) / 2)ifa ≥ 0returnt + (b/2t)ielse return|b|/2t + sign(b)t i
|a| = Math.abs(int)(a)|a + bi| = abs()(a + bi)sign(b) = copySign(1d, b)
NaN if either real or imaginary part of the
input argument is NaN.
Examples:
sqrt(1 ± INFINITY i) = INFINITY + NaN i
sqrt(INFINITY + i) = INFINITY + 0i
sqrt(-INFINITY + i) = 0 + INFINITY i
sqrt(INFINITY ± INFINITY i) = INFINITY + NaN i
sqrt(-INFINITY ± INFINITY i) = NaN ± INFINITY i
this.public Complex sqrt1z()
1 - this2 for this complex
number.
Computes the result directly as
sqrt(ONE.subtract(z.multiply(z))).
NaN if either real or imaginary part of the
input argument is NaN.
1 - this2.public Complex tan()
tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i
where the (real) functions on the right-hand side are
FastMath.sin(double), FastMath.cos(double), FastMath.cosh(double) and
FastMath.sinh(double).
NaN if either real or imaginary part of the
input argument is NaN.
Examples:
tan(a ± INFINITY i) = 0 ± i
tan(±INFINITY + bi) = NaN + NaN i
tan(±INFINITY ± INFINITY i) = NaN + NaN i
tan(±π/2 + 0 i) = ±INFINITY + NaN i
this.public Complex tanh()
tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i
where the (real) functions on the right-hand side are
FastMath.sin(double), FastMath.cos(double), FastMath.cosh(double) and
FastMath.sinh(double).
NaN if either real or imaginary part of the
input argument is NaN.
Examples:
tanh(a ± INFINITY i) = NaN + NaN i
tanh(±INFINITY + bi) = ±1 + 0 i
tanh(±INFINITY ± INFINITY i) = NaN + NaN i
tanh(0 + (π/2)i) = NaN + INFINITY i
this.public double getArgument()
Math.atan2 handles them,
essentially treating finite parts as zero in the presence of an
infinite coordinate and returning a multiple of pi/4 depending on
the signs of the infinite parts.
See the javadoc for Math.atan2 for full details.
this.
public List<Complex> nthRoot(int n)
throws NotPositiveException
zk = abs1/n (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))
for k=0, 1, ..., n-1, where abs and phi
are respectively the modulus and
argument of this complex number.
NaN is returned.
if neither part is NaN, but at least one part is infinite, the result
is a one-element list containing INF.
n - Degree of root.
n-th roots of this.
NotPositiveException - if n <= 0.
protected Complex createComplex(double realPart,
double imaginaryPart)
realPart - Real part.imaginaryPart - Imaginary part.
valueOf(double, double)
public static Complex valueOf(double realPart,
double imaginaryPart)
realPart - Real part.imaginaryPart - Imaginary part.
public static Complex valueOf(double realPart)
realPart - Real part.
protected final Object readResolve()
createComplex(double, double) to
deserialize properly.
public ComplexField getField()
Field to which the instance belongs.
getField in interface FieldElement<Complex>Field to which the instance belongspublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||