JADE v6.1

com.dautelle.math.numbers
Class Complex

java.lang.Object
  extended byjava.lang.Number
      extended bycom.dautelle.math.numbers.RealtimeNumber
          extended bycom.dautelle.math.numbers.Complex
All Implemented Interfaces:
Operable, Realtime, Representable, java.io.Serializable

public final class Complex
extends RealtimeNumber

This class represents an immutable complex number.

Version:
4.0, February 29, 2003
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Nested Class Summary
static class Complex.Value
          This inner class represents a mutable image of an immutable Complex.
 
Nested classes inherited from class com.dautelle.math.numbers.RealtimeNumber
RealtimeNumber.Factory
 
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
 Complex add(Complex that)
          Returns the sum of this complex with the one specified.
 java.lang.StringBuffer appendTo(java.lang.StringBuffer sb)
          Appends the the text representation of this complex number using its cartesian form to the StringBuffer argument.
 double argument()
          Returns the argument of this complex number.
 Complex conjugate()
          Returns the conjugate of this complex number.
 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 magnitude of this Complex as a double.
 boolean equals(Complex that, double tolerance)
          Indicates if two complexes are "sufficiently" alike to be considered equal.
static boolean equals(Matrix A, Matrix B, double tolerance)
          Indicates if two complex matrices 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.
 float floatValue()
          Returns the magnitude of this Complex as a float.
 int hashCode()
          Returns the hash code for this complex number.
 double imaginary()
          Returns the imaginary component of this complex number.
 int intValue()
          Returns the magnitude of this Complex as an int.
 Complex inverse()
          Returns the inverse of this complex.
 boolean isInfinite()
          Indicates if either the real or imaginary component of this complex is infinite.
 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 magnitude of this Complex as a long.
 double magnitude()
          Returns the magnitude of this complex number, also referred to as the "modulus" or "length".
 Complex multiply(Complex that)
          Returns the product of this complex with the one specified.
 Complex multiply(double k)
          Returns this complex multiplied by the specified factor.
 Complex negate()
          Returns the negation of this complex.
 Operable opposite()
          Returns the additive inverse of this object.
 Operable plus(Operable that)
          Returns the sum of this object 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.
 double real()
          Returns the real component of this complex number.
 Operable reciprocal()
          Returns the multiplicative inverse of this object.
 Complex sqrt()
          Returns one of the two square root of this complex number.
 Complex subtract(Complex that)
          Returns the difference between this complex and the one specified.
 Operable times(Operable that)
          Returns the product of this object with the one specified.
 java.lang.String toString()
          Returns the text representation of this complex number using its cartesian form.
 void toXml(XmlElement xml)
          Sets the attributes and content of the XML element corresponding to this object.
static Complex valueOf(java.lang.CharSequence chars)
          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.
static Complex valueOf(XmlElement xml)
          XML factory method.
 
Methods inherited from class com.dautelle.math.numbers.RealtimeNumber
clone, export, isLocalObject, isPoolObject, pow, recycle, toHeap
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
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:
real(), imaginary()

valueOf

public static Complex valueOf(java.lang.CharSequence chars)
Returns the complex number for the specified character sequence. The character sequence must contain the cartesian form of the complex number to return. For example: "1.0 + 2.0i", "1.3 - 2.5i").

Parameters:
chars - the character sequence.
Returns:
the corresponding real number.
Throws:
java.lang.NumberFormatException - if this character sequence does not contain a parsable complex number.

valueOf

public static Complex valueOf(XmlElement xml)
XML factory method.

Parameters:
xml - the XML element describing the complex number to return (e.g. <math:Complex real="0.0" imaginary="1.0"/>).
Returns:
a new complex number as described by the specified xml element.

isInfinite

public final 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 final 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.

real

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

Returns:
the real component.

imaginary

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

Returns:
the imaginary component.

negate

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

Returns:
-this.

add

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

Parameters:
that - the complex to be added.
Returns:
this + that.

subtract

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

Parameters:
that - the complex to be subtracted.
Returns:
this - that.

multiply

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

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

multiply

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

Parameters:
that - the complex multiplier.
Returns:
this * that.

inverse

public Complex inverse()
Returns the inverse of this 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 static boolean equals(Matrix A,
                             Matrix B,
                             double tolerance)
Indicates if two complex matrices are "sufficiently" alike to be considered equal.

Parameters:
A - the first complex matrix.
B - the second complex matrix.
tolerance - the maximum difference between their complex elements before they are considered not equal.
Returns:
true if A and B are considered equal; false otherwise.
Throws:
java.lang.ClassCastException - if A or B are not exclusively composed of complex numbers.
See Also:
equals(Complex, double)

equals

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

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.

Returns:
the hash code value.

appendTo

public java.lang.StringBuffer appendTo(java.lang.StringBuffer sb)
Appends the the text representation of this complex number using its cartesian form to the StringBuffer argument. For example: "1.0 + 2.0i", "1.3 - 2.5i").

Parameters:
sb - the StrinBuffer to append.
Returns:
the specified StrinBuffer.

toString

public java.lang.String toString()
Returns the text representation of this complex number using its cartesian form. For example: "1.0 + 2.0i", "1.3 - 2.5i").

Returns:
the text representation of this complex number.

intValue

public int intValue()
Returns the magnitude of this Complex as an int.

Returns:
(int) magnitude()

longValue

public long longValue()
Returns the magnitude of this Complex as a long.

Returns:
(long) magnitude()

floatValue

public float floatValue()
Returns the magnitude of this Complex as a float.

Returns:
(float) magnitude()

doubleValue

public double doubleValue()
Returns the magnitude of this Complex as a double.

Returns:
magnitude()

plus

public Operable plus(Operable that)
Description copied from interface: Operable
Returns the sum of this object with the one specified.

Parameters:
that - the object to be added.
Returns:
this + that.

opposite

public Operable opposite()
Description copied from interface: Operable
Returns the additive inverse of this object. It is the object such as this.plus(this.opposite()) == ZERO, with ZERO being the additive identity.

Returns:
-this.

times

public Operable times(Operable that)
Description copied from interface: Operable
Returns the product of this object with the one specified.

Parameters:
that - the object multiplier.
Returns:
this * that.

reciprocal

public Operable reciprocal()
Description copied from interface: Operable
Returns the multiplicative inverse of this object. It it the object such as this.times(this.reciprocal()) == ONE , with ONE being the multiplicative identity.

Returns:
ONE / this.

toXml

public void toXml(XmlElement xml)
Description copied from interface: Representable
Sets the attributes and content of the XML element corresponding to this object.

Parameters:
xml - the XML element to set according to this object's desired XML representation.

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.