|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.lang.Number
com.numericalmethod.suanshu.number.complex.Complex
public class Complex
A complex number is a number consisting of a real number part and an imaginary number part.
It is normally written in the form a + bi, where a and b are real numbers,
and i is the square root of minus one.
Complex extends the Number system, and is a Field.
This class is immutable.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.numericalmethod.suanshu.mathstructure.Field |
|---|
Field.InverseNonExistent |
| Field Summary | |
|---|---|
static Complex |
I
the square root of -1;
a number representing 0.0 + 1.0i |
double |
imaginary
the imaginary part of this complex number |
static Complex |
NaN
a number representing a Not-a-Number ( NaN) value of type Complex |
static Complex |
NEGATIVE_INFINITY
a number representing the negative infinity of type Complex |
static Complex |
ONE
a number representing 1.0 + 0.0i |
static Complex |
POSITIVE_INFINITY
a number representing the positive infinity of type Complex |
double |
real
the real part of this complex number |
static Complex |
ZERO
a number representing 0.0 + 0.0i |
| Constructor Summary | |
|---|---|
Complex(double a)
Construct a complex number from a real number a. |
|
Complex(double a,
double b)
Construct a complex number from the real and imaginary parts. |
|
| Method Summary | |
|---|---|
Complex |
add(Complex that)
+ : G × G → G |
double |
arg()
Get the θ of the complex number's polar representation. |
int |
compare(java.lang.Number that,
double epsilon)
Compare this and that numbers up to a precision. |
Complex |
conjugate()
Conjugate of (a + bi) is (a - bi). |
Complex |
divide(Complex that)
Compute the quotient of this complex number and that complex number. |
double |
doubleValue()
|
boolean |
equals(java.lang.Object obj)
|
float |
floatValue()
|
static Complex |
fromPolar(double r,
double theta)
Factory method to construct a complex number from the polar form: (r, θ). |
int |
hashCode()
|
int |
intValue()
Deprecated. Not supported yet. |
Complex |
inverse()
For each a in F, there exists an element b in F such that
a × b = b × a = 1
That is, it is the object such as
this.multiply(this.inverse()) == this.ONE |
static boolean |
isInfinite(Complex z)
Check if this complex number is an infinity; i.e., the number is not a NaN and
either the real or the imaginary part is infinite, c.f., Double.isInfinite(). |
static boolean |
isNaN(Complex z)
Check if this complex number is a NaN;
i.e., either the real or the imaginary part is a NaN. |
static boolean |
isReal(Complex z)
Check if this complex number is a real number; i.e., the imaginary part is 0. |
long |
longValue()
Deprecated. Not supported yet. |
Complex |
minus(Complex that)
- : G × G → G
- is not in the definition of of an additive group but can be deduced. |
double |
modulus()
Get the modulus. |
Complex |
multiply(Complex that)
Compute the product of this complex number and that complex number. |
Complex |
ONE()
A number representing 1.0 + 0.0i. |
Complex |
opposite()
For each a in G, there exists an element b in G such that a + b = b + a = 0
That is, it is the object such as
this.add(this.opposite()) == this.ZERO |
java.lang.Double |
toDouble()
Cast the complex number to a Double if it is a real number. |
java.lang.String |
toString()
|
Complex |
ZERO()
A number representing 0.0 + 0.0i. |
| Methods inherited from class java.lang.Number |
|---|
byteValue, shortValue |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Complex I
-1;
a number representing 0.0 + 1.0i
public static final Complex ZERO
0.0 + 0.0i
public static final Complex ONE
1.0 + 0.0i
public static final Complex POSITIVE_INFINITY
public static final Complex NEGATIVE_INFINITY
public static final Complex NaN
NaN) value of type Complex
public final double real
public final double imaginary
| Constructor Detail |
|---|
public Complex(double a,
double b)
a - the real partb - the imaginary partpublic Complex(double a)
a.
a - the real part| Method Detail |
|---|
public static Complex fromPolar(double r,
double theta)
(r, θ).
r - a radiustheta - an angle
Complex object created from the polar form (r, θ)public static boolean isReal(Complex z)
z - a complex number
true iff the imaginary part is 0public static boolean isNaN(Complex z)
NaN;
i.e., either the real or the imaginary part is a NaN.
z - a complex number
true iff either the real or the imaginary part is a NaNpublic static boolean isInfinite(Complex z)
NaN and
either the real or the imaginary part is infinite, c.f., Double.isInfinite().
z - a complex number
true iff either the real or the imaginary part is a NaNpublic double modulus()
The modulus is the same as the square root of itself multiplied by its conjugate, namely
this.modulus() * this.modulus() == this.multiply(this.conjugate())
To reduce the chance of overflow, this is implemented as:
|a + bi| = |a| sqrt(1 + (b/a)2)if|a| > |b|
|a + bi| = |b| sqrt(1 + (a/b)2)otherwise
Math.hypot() is used for the native implementation of this approach.
Math.hypot(double, double)public double arg()
θ of the complex number's polar representation.
(r, θ)public java.lang.Double toDouble()
Double if it is a real number.
Double if this complex number is a real number
java.lang.IllegalArgumentException - if this complex number is not a real numberpublic Complex conjugate()
(a + bi) is (a - bi).
@Deprecated public int intValue()
intValue in class java.lang.Number@Deprecated public long longValue()
longValue in class java.lang.Numberpublic float floatValue()
floatValue in class java.lang.Numberpublic double doubleValue()
doubleValue in class java.lang.Numberpublic Complex add(Complex that)
AbelianGroup+ : G × G → G
add in interface AbelianGroup<Complex>that - the object to be added
this + thatpublic Complex minus(Complex that)
AbelianGroup- : G × G → G
- is not in the definition of of an additive group but can be deduced.
This function is provided for convenience purpose.
It is equivalent to
this.add(that.opposite())
minus in interface AbelianGroup<Complex>that - the object to be subtracted (subtrahend)
this - thatpublic Complex opposite()
AbelianGroupa + b = b + a = 0
That is, it is the object such as
this.add(this.opposite()) == this.ZERO
opposite in interface AbelianGroup<Complex>-this
public Complex inverse()
throws Field.InverseNonExistent
FieldF, there exists an element b in F such that
a × b = b × a = 1
That is, it is the object such as
this.multiply(this.inverse()) == this.ONE
inverse in interface Field<Complex>1 / this if it exists
Field.InverseNonExistent - if the inverse does not existpublic Complex divide(Complex that)
a + bi ac + bd + (bc - ad)i
-------- = -------------------------------
c + di c2 + d2
c.f.
Efficient scaling for complex division by Douglas M. Priest Sun Microsystems, Menlo Park, CA ACM Transactions on Mathematical Software (TOMS) archive Volume 30, Issue 4 (December 2004) Pages: 389 - 401
ABSTRACT
We develop a simple method for scaling to avoid overflow and harmful underflow in complex division. The method guarantees that no overflow will occur unless at least one component of the quotient must overflow, otherwise the normwise error in the computed result is at most a few units in the last place. Moreover, the scaling requires only four floating point multiplications and a small amount of integer arithmetic to compute the scale factor. Thus, on many modern CPUs, our method is both safer and faster than Smith's widely used algorithm.
divide in interface Field<Complex>that - the denominator
this / that
java.lang.ArithmeticException - if division by zero happenspublic Complex multiply(Complex that)
(a + bi)(c + di) = (ac - bd) + (ad + bc)i
A more efficient implementation is used (1 less multiplication):
(a + bi)(c + di) = (ac - bd) + ((a + b)(c + d) - ac - bd)i
multiply in interface Monoid<Complex>that - the multiplicand
this * thatpublic Complex ZERO()
0.0 + 0.0i.
ZERO in interface AbelianGroup<Complex>new Complex(0.0, 0.0)public Complex ONE()
1.0 + 0.0i.
ONE in interface Monoid<Complex>new Complex(1.0, 0.0)
public int compare(java.lang.Number that,
double epsilon)
NumberUtils.Comparable
compare in interface NumberUtils.Comparable<Complex>that - a Number.
Because a number can be represented in multiple ways, e.g., 0 = 0 + 0i, the implementation may need to check Object type.epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||