JScience v4.3

org.jscience.mathematics.number
Class Complex

java.lang.Object
  extended by java.lang.Number
      extended by org.jscience.mathematics.number.Number<Complex>
          extended by org.jscience.mathematics.number.Complex
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Complex>, javolution.lang.Immutable, javolution.lang.Realtime, javolution.lang.ValueType, javolution.xml.XMLSerializable, Field<Complex>, GroupAdditive<Complex>, GroupMultiplicative<Complex>, Ring<Complex>, Structure<Complex>

public final class Complex
extends Number<Complex>
implements Field<Complex>

This class represents an immutable complex number.

Version:
3.0, February 13, 2006
Author:
Jean-Marie Dautelle
See Also:
Wikipedia: Complex number, Serialized Form

Field Summary
static Complex I
          The imaginary unit i.
static Complex ONE
          The complex number one.
static Complex ZERO
          The complex number zero.
 
Method Summary
 double argument()
          Returns the argument of this complex number.
 int compareTo(Complex that)
          Compares two complex numbers, the real components are compared first, then if equal, the imaginary components.
 Complex conjugate()
          Returns the conjugate of this complex number.
 Complex copy()
          Returns a copy of this number allocated by the calling thread (possibly on the stack).
 Complex divide(Complex that)
          Returns this complex divided by the specified complex.
 Complex divide(double k)
          Returns this complex divided by the specified factor.
 double doubleValue()
          Returns the real component of this Complex number as a double.
 boolean equals(Complex that, double tolerance)
          Indicates if two complexes are "sufficiently" alike to be considered equal.
 boolean equals(java.lang.Object that)
          Compares this complex against the specified Object.
 Complex exp()
          Returns the exponential number e raised to the power of this complex.
 double getImaginary()
          Returns the imaginary component of this complex number.
 double getReal()
          Returns the real component of this complex number.
 int hashCode()
          Returns the hash code for this complex number.
 Complex inverse()
          Returns the inverse of this complex.
 boolean isInfinite()
          Indicates if either the real or imaginary component of this complex is infinite.
 boolean isLargerThan(Complex that)
          Compares the magnitude of this complex number with the magnitude of the complex number specified.
 boolean isNaN()
          Indicates if either the real or imaginary component of this complex is not a number.
 Complex log()
          Returns the principal natural logarithm (base e) of this complex.
 long longValue()
          Returns the real component of this Complex number as a long.
 double magnitude()
          Returns the magnitude of this complex number, also referred to as the "modulus" or "length".
 Complex minus(Complex that)
          Returns the difference between this complex and the one specified.
 Complex opposite()
          Returns the negation of this complex.
 Complex plus(Complex that)
          Returns the sum of this complex with the one specified.
 Complex pow(Complex that)
          Returns this complex raised to the power of the specified complex exponent.
 Complex pow(double e)
          Returns this complex raised to the specified power.
 Complex sqrt()
          Returns one of the two square root of this complex number.
 Complex times(Complex that)
          Returns the product of this complex with the one specified.
 Complex times(double k)
          Returns this complex multiplied by the specified factor.
 javolution.text.Text toText()
          Returns the text representation of this complex number.
static Complex valueOf(java.lang.CharSequence csq)
          Returns the complex number for the specified character sequence.
static Complex valueOf(double real, double imaginary)
          Returns the complex number having the specified real and imaginary components.
 
Methods inherited from class org.jscience.mathematics.number.Number
byteValue, floatValue, intValue, isGreaterThan, isLessThan, pow, shortValue, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Complex ZERO
The complex number zero.


ONE

public static final Complex ONE
The complex number one.


I

public static final Complex I
The imaginary unit i.

Method Detail

valueOf

public static Complex valueOf(double real,
                              double imaginary)
Returns the complex number having the specified real and imaginary components.

Parameters:
real - the real component of this complex number.
imaginary - the imaginary component of this complex number.
Returns:
the corresponding complex number.
See Also:
getReal(), getImaginary()

valueOf

public static Complex valueOf(java.lang.CharSequence csq)
Returns the complex number for the specified character sequence.

Parameters:
csq - the character sequence.
Returns:
TextFormat.getInstance(Complex.class).parse(csq)
Throws:
java.lang.IllegalArgumentException - if the character sequence does not contain a parsable complex number.
See Also:
TextFormat.getInstance(Class)

isInfinite

public boolean isInfinite()
Indicates if either the real or imaginary component of this complex is infinite.

Returns:
true if this complex is infinite; false otherwise.

isNaN

public boolean isNaN()
Indicates if either the real or imaginary component of this complex is not a number.

Returns:
true if this complex is NaN; false otherwise.

getReal

public double getReal()
Returns the real component of this complex number.

Returns:
the real component.

getImaginary

public double getImaginary()
Returns the imaginary component of this complex number.

Returns:
the imaginary component.

opposite

public Complex opposite()
Returns the negation of this complex.

Specified by:
opposite in interface GroupAdditive<Complex>
Returns:
-this.

plus

public Complex plus(Complex that)
Returns the sum of this complex with the one specified.

Specified by:
plus in interface GroupAdditive<Complex>
Parameters:
that - the complex to be added.
Returns:
this + that.

minus

public Complex minus(Complex that)
Returns the difference between this complex and the one specified.

Overrides:
minus in class Number<Complex>
Parameters:
that - the complex to be subtracted.
Returns:
this - that.

times

public Complex times(double k)
Returns this complex multiplied by the specified factor.

Parameters:
k - the factor multiplier.
Returns:
this * k.

times

public Complex times(Complex that)
Returns the product of this complex with the one specified.

Specified by:
times in interface GroupMultiplicative<Complex>
Specified by:
times in interface Ring<Complex>
Parameters:
that - the complex multiplier.
Returns:
this * that.

inverse

public Complex inverse()
Returns the inverse of this complex.

Specified by:
inverse in interface GroupMultiplicative<Complex>
Returns:
1 / this.

divide

public Complex divide(double k)
Returns this complex divided by the specified factor.

Parameters:
k - the factor divisor.
Returns:
this / k.

divide

public Complex divide(Complex that)
Returns this complex divided by the specified complex.

Parameters:
that - the complex divisor.
Returns:
this / that.

conjugate

public Complex conjugate()
Returns the conjugate of this complex number.

Returns:
(this.real(), - this.imaginary()).

magnitude

public double magnitude()
Returns the magnitude of this complex number, also referred to as the "modulus" or "length".

Returns:
the magnitude of this complex number.

argument

public double argument()
Returns the argument of this complex number. It is the angle in radians, measured counter-clockwise from the real axis.

Returns:
argument of this complex number.

sqrt

public Complex sqrt()
Returns one of the two square root of this complex number.

Returns:
sqrt(this).

exp

public Complex exp()
Returns the exponential number e raised to the power of this complex. Note: ePI*i = -1

Returns:
exp(this).

log

public Complex log()
Returns the principal natural logarithm (base e) of this complex. Note: There are an infinity of solutions.

Returns:
log(this).

pow

public Complex pow(double e)
Returns this complex raised to the specified power.

Parameters:
e - the exponent.
Returns:
this**e.

pow

public Complex pow(Complex that)
Returns this complex raised to the power of the specified complex exponent.

Parameters:
that - the exponent.
Returns:
this**that.

equals

public boolean equals(Complex that,
                      double tolerance)
Indicates if two complexes are "sufficiently" alike to be considered equal.

Parameters:
that - the complex to compare with.
tolerance - the maximum magnitude of the difference between them before they are considered not equal.
Returns:
true if they are considered equal; false otherwise.

equals

public boolean equals(java.lang.Object that)
Compares this complex against the specified Object.

Specified by:
equals in class Number<Complex>
Parameters:
that - the object to compare with.
Returns:
true if the objects are the same; false otherwise.

hashCode

public int hashCode()
Returns the hash code for this complex number.

Specified by:
hashCode in class Number<Complex>
Returns:
the hash code value.

toText

public javolution.text.Text toText()
Returns the text representation of this complex number.

Specified by:
toText in interface javolution.lang.Realtime
Specified by:
toText in class Number<Complex>
Returns:
TextFormat.getInstance(Complex.class).format(this)
See Also:
TextFormat.getInstance(Class)

longValue

public long longValue()
Returns the real component of this Complex number as a long.

Specified by:
longValue in class Number<Complex>
Returns:
(long) this.getReal()

doubleValue

public double doubleValue()
Returns the real component of this Complex number as a double.

Specified by:
doubleValue in class Number<Complex>
Returns:
(double) this.getReal()

compareTo

public int compareTo(Complex that)
Compares two complex numbers, the real components are compared first, then if equal, the imaginary components.

Specified by:
compareTo in interface java.lang.Comparable<Complex>
Specified by:
compareTo in class Number<Complex>
Parameters:
that - the complex number to be compared with.
Returns:
-1, 0, 1 based upon the ordering.

isLargerThan

public boolean isLargerThan(Complex that)
Compares the magnitude of this complex number with the magnitude of the complex number specified.

Specified by:
isLargerThan in class Number<Complex>
Parameters:
that - the complex number to be compared with.
Returns:
|this| > |that|

copy

public Complex copy()
Description copied from class: Number
Returns a copy of this number allocated by the calling thread (possibly on the stack).

Specified by:
copy in interface javolution.lang.ValueType
Specified by:
copy in class Number<Complex>
Returns:
an identical and independant copy of this number.

JScience v4.3

Copyright © 2006 JScience.