@CodeReview(reviewer="Kevin R. Dixon",date="2008-02-08",changesNeeded=false,comments={"Fixed one or two typos in comments.","Should ComplexNumber be an interface, with implementations being rectangular and polar?","Certainly doesn\'t need to be addressed now, but something to think about.","Otherwise, looks fine."}) @CodeReview(reviewer="Jonathan McClain",date="2006-05-15",changesNeeded=false,comments="Looks good, but advise a second person go over this because there is a lot of math here.") @PublicationReference(author="Wikipedia", title="Complex number", type=WebPage, year=2008, url="http://en.wikipedia.org/wiki/Complex_number") public class ComplexNumber extends AbstractField<ComplexNumber> implements java.io.Serializable
| Constructor and Description |
|---|
ComplexNumber()
Creates a new instance of ComplexNumber with zero magnitude.
|
ComplexNumber(ComplexNumber other)
Copy constructor
|
ComplexNumber(double realPart,
double imaginaryPart)
Creates a new instance of ComplexNumber using the specified complex parts
|
| Modifier and Type | Method and Description |
|---|---|
ComplexNumber |
clone()
Returns a deep copy of this
|
ComplexNumber |
computeExponent()
Computes the natural-base exponent of the complex number, such that
this = log(exp(this)) = exp(log(this))
|
ComplexNumber |
computeNaturalLogarithm()
Computes the natural-base logarithm of the complex number, such that
this = log(exp(this)) = exp(log(this))
|
ComplexNumber |
conjugate()
Switches the sign of the imaginary part of this complex number.
|
void |
conjugateEquals()
Switches the sign of the imaginary part of this complex number.
|
ComplexNumber |
divide(ComplexNumber other)
Arithmetic division of this by other using polar coordinates:
magnitude = this.magnitude / other.magnitude
phase = this.phase - other.phase
answer.realPart = magnitude * cos( phase )
answer.imaginaryPart = magnitude * sin( phase )
|
ComplexNumber |
dividedBy(ComplexNumber other)
Deprecated.
Use divide.
|
void |
dividedByEquals(ComplexNumber other)
Deprecated.
Use divideEquals.
|
void |
divideEquals(ComplexNumber other)
Inline arithmetic division of this by other:
this.magnitude /= other.magnitude
this.phase -= other.phase
|
void |
dotTimesEquals(ComplexNumber other)
Inline element-wise multiplication of
this and
other |
boolean |
equals(ComplexNumber other,
double effectiveZero)
Determines if two RingType objects are effectively equal
|
boolean |
equals(java.lang.Object other)
Determines if two RingType objects are equal
|
double |
getImaginaryPart()
Returns the imaginary portion of the complex number,
no computation needed
|
double |
getMagnitude()
Computes the magnitude of the complex number, sometimes called the
length of the number.
|
double |
getPhase()
Computes the phase in radians of the complex number, sometimes called
the angle.
|
double |
getRealPart()
Returns the real portion of the complex number, no computation needed
|
int |
hashCode() |
void |
inverseEquals()
Changes this value to be its inverse.
|
boolean |
isZero(double effectiveZero)
Determines if this ring is equal to zero using the element-wise effective
zero value.
|
void |
minusEquals(ComplexNumber other)
Inline arithmetic subtraction of
other from
this |
void |
plusEquals(ComplexNumber number)
Inline addition between this and the complex number
|
void |
scaledPlusEquals(double scaleFactor,
ComplexNumber other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
void |
scaleEquals(double scaleFactor)
Inline element-wise scaling of
this by
scaleFactor |
void |
setImaginaryPart(double imaginaryPart)
Sets the imaginary portion of the complex number
|
void |
setRealPart(double realPart)
Sets the real part of the complex number
|
ComplexNumber |
times(ComplexNumber other)
Arithmetic multiplication of this and other using polar coordinates:
magnitude = this.magnitude * other.magnitude
phase = this.phase + other.phase
answer.realPart = magnitude * cos( phase )
answer.imaginaryPart = magnitude * sin( phase )
|
void |
timesEquals(ComplexNumber other)
Inline arithmetic multiplication of this and other:
this.magnitude *= other.magnitude
this.phase += other.phase
|
java.lang.String |
toString() |
inversedotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, zerofinalize, getClass, notify, notifyAll, wait, wait, waitdotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, zeropublic ComplexNumber()
public ComplexNumber(double realPart,
double imaginaryPart)
realPart - real part of the complex numberimaginaryPart - imaginary part of the complex numberpublic ComplexNumber(ComplexNumber other)
other - ComplexNumber to copypublic ComplexNumber clone()
clone in interface Ring<ComplexNumber>clone in interface CloneableSerializableclone in class AbstractRing<ComplexNumber>public void plusEquals(ComplexNumber number)
plusEquals in interface Ring<ComplexNumber>number - number to add this topublic double getMagnitude()
public double getPhase()
public ComplexNumber computeExponent()
public ComplexNumber computeNaturalLogarithm()
public void dotTimesEquals(ComplexNumber other)
Ringthis and
otherdotTimesEquals in interface Ring<ComplexNumber>other - elements of other will be multiplied to the corresponding
elements of thispublic void minusEquals(ComplexNumber other)
Ringother from
thisminusEquals in interface Ring<ComplexNumber>other - object to subtract from thispublic void scaleEquals(double scaleFactor)
Ringthis by
scaleFactorscaleEquals in interface Ring<ComplexNumber>scaleFactor - amount to scale the elements of thispublic void scaledPlusEquals(double scaleFactor,
ComplexNumber other)
Ringthis and other after
element-wise scaling of other by scaleFactor.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x += a * y. It is typically a more efficient way of doing
this.plusEquals(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledPlusEquals in interface Ring<ComplexNumber>scaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public ComplexNumber times(ComplexNumber other)
times in interface EuclideanRing<ComplexNumber>times in class AbstractEuclideanRing<ComplexNumber>other - complex number by which to multiply thispublic void timesEquals(ComplexNumber other)
timesEquals in interface EuclideanRing<ComplexNumber>other - complex number by which to multiple thispublic ComplexNumber divide(ComplexNumber other)
divide in interface EuclideanRing<ComplexNumber>divide in class AbstractEuclideanRing<ComplexNumber>other - complex number by which to divide thispublic void divideEquals(ComplexNumber other)
divideEquals in interface EuclideanRing<ComplexNumber>other - complex number by which to divide this@Deprecated public ComplexNumber dividedBy(ComplexNumber other)
other - The other complex number.@Deprecated public void dividedByEquals(ComplexNumber other)
other - The other complex number.public void inverseEquals()
FieldinverseEquals in interface Field<ComplexNumber>public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object other)
Ringequals in interface Ring<ComplexNumber>equals in class java.lang.Objectother - RingType to compare against thispublic boolean equals(ComplexNumber other, double effectiveZero)
Ringequals in interface Ring<ComplexNumber>other - RingType to compare against thiseffectiveZero - tolerance threshold for element-wise equalitypublic java.lang.String toString()
toString in class java.lang.Objectpublic double getRealPart()
public void setRealPart(double realPart)
realPart - real portion of the complex numberpublic double getImaginaryPart()
public void setImaginaryPart(double imaginaryPart)
imaginaryPart - imaginary portion of the complex numberpublic void conjugateEquals()
public ComplexNumber conjugate()
public boolean isZero(double effectiveZero)
RingisZero in interface Ring<ComplexNumber>effectiveZero - Tolerance threshold for element-wise equality