|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.rubecula.util.Item com.rubecula.jquantity.Complex
Representation of a Complex Number
Objects of this class represent complex numbers defined on one side or the
other of the EL (exponential-log) plane. Numbers on "log" side are in polar
form {r,theta,k), while numbers on the "exponential" side are in cartesian
form (x,y).
The pair of two peer points (one on each side of the plane)
is called a "pair".
The class Complex is a subclass of Item
,
with instance fields for the real part, side, and, if appropriate, the
imaginary part, and possibly the branch.
Nested Class Summary | |
private class |
Complex.ComplexException
|
Field Summary | |
private int |
_Branch
If this Complex is defined on the polar (logarithmic) side, then this integer represents which "branch" the number is defined on. |
private boolean |
_Constant
This instance field signifies if this instance of Complex has been designated a constant. |
private Value |
_I
The Value instance representing the imaginary part of this Complex. |
private java.lang.String |
_Identifier
|
private boolean |
_Polar
Which side of the EL plane is the number defined on. |
private Value |
_R
The Value instance representing the real part of this Complex. |
static Complex |
$0
The constant value of 0 (Cartesian/Exponential side). |
static Complex |
$1
The constant real value of 1 (Cartesian/Exponential side). |
static Complex |
$I
The constant imaginary value of 1 (Cartesian/Exponential side). |
Fields inherited from class com.rubecula.util.Item |
JQUANTITY_TEST |
Constructor Summary | |
Complex()
Secondary constructor for a zero-valued real-only cartesian Complex instance. |
|
Complex(boolean polar)
Secondary constructor for a zero-valued real-only Complex instance which, if polar, is defined on the primary branch (k=0). |
|
Complex(boolean polar,
java.lang.String identifier)
Secondary constructor for a zero-valued real-only Complex instance which, if polar, is defined on the primary branch (k=0). |
|
Complex(java.lang.String identifier)
Secondary constructor for a zero-valued real-only cartesian Complex instance. |
|
Complex(Value r)
Secondary constructor for a real-only cartesian Complex instance. |
|
Complex(Value r,
boolean polar)
Secondary constructor for a real-only Complex instance which, if polar, is defined on the primary branch (k=0). |
|
Complex(Value r,
boolean polar,
java.lang.String identifier)
Secondary constructor for a real-only Complex instance which, if polar, is defined on the primary branch (k=0). |
|
Complex(Value r,
java.lang.String identifier)
Secondary constructor for a real-only cartesian Complex instance. |
|
Complex(Value r,
Value i)
Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0). |
|
Complex(Value r,
Value i,
boolean polar)
Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0). |
|
Complex(Value r,
Value i,
boolean polar,
int k,
java.lang.String identifier)
Primary constructor for a Complex instance. |
|
Complex(Value r,
Value i,
boolean polar,
java.lang.String identifier)
Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0). |
|
Complex(Value r,
Value i,
java.lang.String identifier)
Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0). |
Method Summary | |
void |
add(Complex addend)
MUTATING Instance method to add a Complex into this object. |
Trigonometrical |
arctanX2()
Method to evaluate the arctangent function. |
protected void |
assertMutable()
This method tests whether this particular instance is mutable, i.e. it has not been designated a constant. |
java.lang.String |
audit(java.lang.String label)
Method to return a detailed string from an arithmetical object for debugging purposes. |
private void |
cast(boolean polar)
MUTATING Method to force a Complex to the opposite side of the plane, thus moving the point so that the real and imaginary values do not change numerically (other than possible factoring). |
java.lang.Object |
clone()
Creates and returns a copy of this object. |
int |
compareTo(Complex val)
Compares this Complex with the specified Complex. |
protected int |
compareTo(Complex val,
boolean strict)
Compares this Complex with the specified Complex. |
Imaginable |
complement()
Method to determine the complex complement (i.e. the conjugate) of this Imaginable. |
private void |
convert(boolean polar)
MUTATING Method to convert a Complex to the opposite side of the plane, keeping the point static, thus requiring that the real and imaginary values do change numerically. |
Complex |
convertValue(boolean polar)
Method to yield an equivalent Complex instance to this, but where the "side" is defined by polar. |
Complex |
difference(Complex subtrahend)
Method to yield the difference of this less subtrahend. |
double |
doubleValue()
Returns the magnitude of this Complex as a double . |
Trigonometrical |
exp()
Method to evaluate the exponential function. |
Divisible |
factored(double factor)
Method to yield the quotient of this divided by factor, and return it as the result. |
Complex |
factored(Rational factor)
Method to yield the quotient of this divided by factor, and return it as the result. |
java.lang.String |
getIdentifier()
Method to get the specific identifier for an object. |
(package private) Value |
getImaginary()
Package-scope method to get only the real part of the Complex. |
(package private) Value |
getReal()
Package-scope method to get only the real part of the Complex. |
Divisible |
inverse()
Method to yield the reciprocal of this and return it as the result. |
(package private) boolean |
isImaginary()
Method to determine if this Complex is purely imaginary. |
boolean |
isMutable()
This method indicates whether this particular instance is mutable, i.e. |
boolean |
isNormal()
Method to determine if this instance is already normalized. |
boolean |
isPolar()
Method to determine if this instance is defined on the polar (log) side as opposed to being defined on the exponential (cartesian) side. |
boolean |
isReal()
Method to determine if this Complex is purely real. |
Trigonometrical |
log()
Method to evaluate the natural log function. |
Value |
magnitude()
Method to determine the magnitude of this Imaginable. |
static void |
main(java.lang.String[] args)
Main method for testing this class. |
Presentable |
makePresentableInstance(Presentation presentation)
Instance method to convert a Presentation into a Presentable. |
Complex |
minus()
Method to determine the negated value of this. |
void |
multiply(Complex multiplicand)
MUTATING Instance method to multiply another Arithmetical into this object. |
void |
negate()
MUTATING Instance method to negate this. |
void |
normalize()
MUTATING instance method to normalize this object. |
static Presentable |
Parse(Presentation presentation)
Create a Complex from a Presentation and return it as a Presentable. |
static Presentable |
Parse(Presentation presentation,
java.lang.String identifier)
Create an explicitly identified Complex from a Presentation and return it as a Presentable. |
static Complex |
Parse(SymbolicPresentation presentation,
java.lang.String identifier)
Translates the SymbolicPresentation representation of a complex number into a Complex. |
Value |
phase()
Method to determine the phase, also known as the argument, of this Imaginable. |
Complex |
pow(BaseNumber power)
Method to yield this raised to the power specified. |
Complex |
pow(Complex power)
Method to yield this raised to the power specified. |
Complex |
pow(double power)
Method to yield this raised to the power specified. |
Complex |
pow(int power)
Method to yield this raised to the power specified. |
Complex |
pow(Item power)
Method to yield this raised to the power specified. |
Presentation |
present(AttrMap attributes)
Convert this Presentable object into a Presentation, according to the set of attributes provided. |
Complex |
product(Complex multiplicand)
Method to yield the product of this and multiplicand. |
Divisible |
quotient(BaseNumber divisor)
Method to divide this by divisor and return the quotient as the result. |
void |
raiseToPower(double power)
MUTATING Instance method to raise this to power x. |
void |
raiseToPower(int power)
MUTATING Instance method to raise this to power x. |
Imaginable |
rotate(Value angle)
Method to rotate this (in Complex space). |
void |
scale(long factor)
MUTATING Instance method to multiply this by a scale factor. |
Mutable |
setConstant()
This method sets this instance to be a constant, i.e. immutable. |
void |
setIdentifier(java.lang.String identifier)
MUTATING Method to set a specific identifier to an object. |
Complex |
square()
Method to yield the square of this. |
Complex |
sum(Complex addend)
Method to yield the sum of this and addend. |
Trigonometrical |
tan_theta_2()
Method to evaluate the tangent function. |
static Complex |
valueOf(BaseNumber number)
Factory method to create a real-valued Complex from a BaseNumber. |
static Complex |
valueOf(java.lang.String string)
Translates the String representation of a Complex into a Complex. |
Methods inherited from class com.rubecula.util.Item |
audit, audit, compareTo, Debug, getClassNameShort, getType, IsDebug, present, SetDebug, test, test, toString, Wrap |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.rubecula.util.Auditable |
audit, audit |
Field Detail |
public static final Complex $0
public static final Complex $1
public static final Complex $I
private java.lang.String _Identifier
private Value _R
private Value _I
private boolean _Polar
private int _Branch
private boolean _Constant
Constructor Detail |
public Complex(Value r, Value i, boolean polar, int k, java.lang.String identifier)
r
- A Value defining the real part of the new Complex. (x or r).i
- A Value defining the imaginary part of the Complex (y or
theta).polar
- True if this Complex is defined on the log side, i.e. as
exp(r + i theta + 2 k pi); false if this number is defined on
the exponential side, i.e. x = i y;k
- The "branch" on which this number is defined.identifier
- The name of this instance (or null).public Complex(Value r, Value i, boolean polar, java.lang.String identifier)
r
- A Value defining the real part of the new Complex. (x or r).i
- A Value defining the imaginary part of the Complex (y or
theta).polar
- True if this Complex is defined on the log side, i.e. as
exp(r + i theta).identifier
- The name of this instance (or null).public Complex(Value r, Value i, java.lang.String identifier)
r
- A Value defining the real part of the new Complex. (x or r).i
- A Value defining the imaginary part of the Complex (y or
theta).identifier
- The name of this instance (or null).public Complex(Value r, boolean polar, java.lang.String identifier)
r
- A Value defining the real part of the new Complex. (x or r).polar
- True if this Complex is defined on the log side, i.e. as
exp(r).identifier
- The name of this instance (or null).public Complex(Value r, java.lang.String identifier)
r
- A Value defining the real part of the new Complex. (x or r).identifier
- The name of this instance (or null).public Complex(boolean polar, java.lang.String identifier)
polar
- True if this Complex is defined on the log side, i.e. as
exp(0).identifier
- The name of this instance (or null).public Complex(java.lang.String identifier)
identifier
- The name of this instance (or null).public Complex(Value r, Value i, boolean polar)
r
- A Value defining the real part of the new Complex. (x or r).i
- A Value defining the imaginary part of the Complex (y or
theta).polar
- True if this Complex is defined on the log side, i.e. as
exp(r + i theta).public Complex(Value r, Value i)
r
- A Value defining the real part of the new Complex. (x or r).i
- A Value defining the imaginary part of the Complex (y or
theta).public Complex(Value r, boolean polar)
r
- A Value defining the real part of the new Complex. (x or r).polar
- True if this Complex is defined on the log side, i.e. as
exp(r).public Complex(Value r)
r
- A Value defining the real part of the new Complex. (x or r).public Complex(boolean polar)
polar
- True if this Complex is defined on the log side, i.e. as
exp(0).public Complex()
Method Detail |
public static Presentable Parse(Presentation presentation, java.lang.String identifier) throws PresentationException
presentation
- A presentation which should be parsed to form a Presentable.identifier
- the explicit identifier for the new Complex
PresentationException
- if the presentation cannot be parsed as a Presentable
object.public static Presentable Parse(Presentation presentation) throws PresentationException
presentation
- A presentation which should be parsed to form a Presentable.
PresentationException
- if the presentation cannot be parsed as a Presentable
object.public static Complex Parse(SymbolicPresentation presentation, java.lang.String identifier) throws PresentationException
presentation
- SymbolicPresentation representation of a complex number.identifier
- A string with which to identify this Complex.
PresentationException
- if the presentation cannot be parsed as a Complex object.public static Complex valueOf(BaseNumber number)
number
- a number for which we require the (widened) Complex.
public static Complex valueOf(java.lang.String string) throws PresentationException
string
- String representation of Complex in the form: x + i y
or r, z pi.
PresentationException
- if the string cannot be parsed as a Complex object.public java.lang.String getIdentifier()
getIdentifier
in interface Identifiable
public void setIdentifier(java.lang.String identifier)
setIdentifier
in interface Nameable
identifier
- the identifier to associate with the object.public java.lang.Object clone()
RationalException
- :
Rational not Cloneable (should be impossible)Cloneable
protected int compareTo(Complex val, boolean strict)
val
- Complex to which this Complex is to be compared.strict
- If strict is true, then the Complex objects are compared
field by field; if false then the two objects are normalized
if necessary before making the comparison. Apparent equality
is then (in the non-strict case) more of an equivalency.
public int compareTo(Complex val)
val
- Complex to which this Complex is to be compared.
public void normalize()
normalize
in interface Normalizable
public boolean isNormal()
Normalizable
isNormal
in interface Normalizable
public java.lang.String audit(java.lang.String label)
audit
in interface Auditable
label
- String: the label to associate with the data
public Presentable makePresentableInstance(Presentation presentation) throws PresentationException
makePresentableInstance
in interface Presentable
presentation
- of a number to be converted into a Presentable number.
PresentationException
- if presentation cannot be parsed appropriately.public Presentation present(AttrMap attributes) throws PresentationException
present
in interface Presentable
attributes
- a map of the required attributes for the presentation.
Supported attributes include:
PresentationException
- if this object cannot be presented with the given
attributes.public Divisible inverse()
inverse
in interface Divisible
public Divisible quotient(BaseNumber divisor) throws InvalidOperandException
quotient
in interface Divisible
divisor
- the number to multiply by this.
InvalidOperandException
- operands are not compatible for the quotient operation.public Divisible factored(double factor)
factored
in interface Divisible
factor
- the scale factor.
public Trigonometrical exp()
log()
.
exp
in interface Trigonometrical
public Trigonometrical log()
exp()
.
log
in interface Trigonometrical
public Trigonometrical arctanX2()
tan_theta_2()
.
arctanX2
in interface Trigonometrical
public Trigonometrical tan_theta_2()
arctanX2()
.
tan_theta_2
in interface Trigonometrical
Value getReal()
Value getImaginary()
public boolean isReal()
boolean isImaginary()
public boolean isPolar()
_Polar
.public Complex factored(Rational factor)
factor
- the scale factor.
public Value magnitude()
magnitude
in interface Imaginable
public Value phase()
phase
in interface Imaginable
public double doubleValue()
double
. This
may involve rounding.
double
.public Imaginable complement()
complement
in interface Imaginable
public Imaginable rotate(Value angle)
rotate
in interface Imaginable
angle
- the angle by which this is to be rotated (counter-clockwise).
public Complex product(Complex multiplicand)
multiplicand
- the Complex which is to be multiplied by this
multiply(Complex)
with argument multiplicand.
Complex.ComplexException
- product(multiplicand): logic errorpublic Complex sum(Complex addend)
addend
- the Complex which is to be multiplied by this
add(Complex)
with
argument addend.
Complex.ComplexException
- sum(addend): logic errorpublic Complex difference(Complex subtrahend)
subtrahend
- the Complex which is to be subtracted from this
minus()
to subtrahend and then
passing this to sum(Complex)
.public Complex minus()
negate()
has been invoked.public Complex square()
product(Complex)
of this with this.public Complex pow(Item power) throws InvalidOperandException
power
- the (Item) power to which this is to be raised.
pow(Complex)
if power is a Complex;
pow(BaseNumber)
if power is a BaseNumber; else throw
exception.
ComplexException(pow(Item):
- not available for power class
InvalidOperandException
public Complex pow(Complex power) throws InvalidOperandException
power
- the (Complex) power to which this is to be raised.
InvalidOperandException
- Complex.pow(Complex): not implemented for this combinationpublic Complex pow(int power)
power
- the (int) power to which this is to be raised.
square()
if
power==2 else return a copy that has undergone
raiseToPower(int)
.public Complex pow(double power)
power
- the (double) power to which this is to be raised.
square()
if
power==2 else return a copy that has undergone
raiseToPower(double)
.public Complex pow(BaseNumber power)
power
- the power to which this is to be raised (a BaseNumber)
private void cast(boolean polar)
polar
- the side of the plane to which this Complex is to be moved.private void convert(boolean polar)
polar
- the side of the plane to which this Complex is to be
converted.public Mutable setConstant()
setConstant
in interface Mutable
public boolean isMutable()
isMutable
in interface Mutable
protected void assertMutable()
public void add(Complex addend) throws InvalidOperandException
addend
- the number to add to this.
InvalidOperandException
- operands are not compatible for the add operation.public void multiply(Complex multiplicand) throws InvalidOperandException
multiplicand
- the number by which this is to be multiplied.
InvalidOperandException
- operands are not compatible for the multiply operation.public void negate()
public void raiseToPower(int power)
power
- the number of times this should be multiplied by itself.public void raiseToPower(double power)
power
- the number of times this should be multiplied by itself.public void scale(long factor)
factor
- the scale factor.public Complex convertValue(boolean polar)
polar
- true if the result is required to be on the log side or false
for the exponential (cartesian) side.
convert(boolean)
.public static void main(java.lang.String[] args)
args
- String[] : the command line options.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |