

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object edu.neu.ccs.XPolynomialComplex
Class XPolynomialComplex
provides an implementation
of a polynomial in one complex variable with complex coefficients.
XPolynomialComplex
fits into the family of functions
that implement FunctionComplex.OneArg
.
For convenience of data entry, XPolynomialComplex
also
implements Stringable
.
Field Summary  
protected SwingPropertyChangeSupport 
changeAdapter
Helper object for property change API. 
protected XComplex[] 
coefficients
The polynomial coefficients or null if no
storage has been allocated. 
private static String 
divisionMessage
Division by zero error message. 
static String 
standardMessage
The standard error message for fromStringData. 
Fields inherited from interface edu.neu.ccs.util.JPTConstants 
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE 
Fields inherited from interface javax.swing.SwingConstants 
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST 
Constructor Summary  
XPolynomialComplex()
The constructor that sets the polynomial to the zero polynomial but allocates no storage for future coefficients. 

XPolynomialComplex(double[][] params)
The constructor that sets the polynomial coefficients to a copy of the given params array. 

XPolynomialComplex(float[][] params)
The constructor that sets the polynomial coefficients to a copy of the given params array. 

XPolynomialComplex(int capacity)
The constructor that sets the polynomial to the zero polynomial and allocates storage with the given capacity. 

XPolynomialComplex(String data)
The constructor that uses fromStringData
to set the polynomial coefficients. 

XPolynomialComplex(String[] strings)
The constructor that uses fromStringArrayData
to set the polynomial coefficients. 

XPolynomialComplex(XComplex[] params)
The constructor that sets the polynomial coefficients to a copy of the given params array. 

XPolynomialComplex(XPolynomialComplex polynomial)
Constructs and initializes an XPolynomialComplex from
the specified XPolynomialComplex object. 
Method Summary  
static XPolynomialComplex 
add(XPolynomialComplex p,
XPolynomialComplex q)
Returns a new polynomial equivalent mathematically to (p + q). 
void 
addPropertyChangeListener(PropertyChangeListener listener)
Registers the given object to listen for property change events generated by this object. 
void 
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Registers the given object to listen for property change events generated by this object with the given property name. 
static XPolynomialComplex[] 
divide(XPolynomialComplex p,
XPolynomialComplex q)
Returns a polynomial array consisting of 2 items: the quotient of p divided by q and the remainder of p divided by q. 
XComplex 
evaluate(XComplex x)
Returns the value of the polynomial at the given x. 
void 
fromStringArrayData(String[] strings)
Defines the data state for this XPolynomialComplex object
from a String array representation of the data state. 
void 
fromStringData(String data)
Defines the data state for this XPolynomialComplex
object from a String representation of the data state. 
int 
getCapacity()
Returns the capacity of the current internal storage, that is, the largest index into which data may be stored without reallocation of the coefficients array. 
XComplex 
getCoefficient(int index)
Returns a copy of the coefficient at the given index. 
XComplex[] 
getCoefficients()
Returns a copy of the polynomial coefficients. 
int 
getDegree()
Returns the degree of the polynomial which is defined to be the highest index whose coefficient is nonzero; by convention, the zero polynomial has degree 1. 
boolean 
isAlmostEqualTo(XPolynomialComplex p,
double epsilon)
Returns true if the given polynomial is almost equal to this polynomial in the sense that all coefficients agree to within the measure epsilon. 
boolean 
isAlmostZero(double epsilon)
Returns true if the polynomial is almost the zero polynomial relative to the measure epsilon, that is, if all of its coefficients have a maxabs value that is less than
or equal to epsilon. 
boolean 
isEqualTo(XPolynomialComplex p)
Returns true if the given polynomial is equal to this
in the sense that the degrees are the same and all coefficients agree
using XComplex.isEqualTo to test equality. 
boolean 
isZero()
Returns true if the polynomial is the zero polynomial. 
double 
maxCoefficient()
Returns the maximum of the method maxabs applied to
the coefficients in this polynomial. 
static XPolynomialComplex 
multiply(XPolynomialComplex p,
XPolynomialComplex q)
Returns a new polynomial equivalent mathematically to (p * q). 
void 
removePropertyChangeListener(PropertyChangeListener listener)
Deregisters the given object from listening for property change events generated by this object. 
void 
removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Deregisters the given object from listening for property change events generated by this object with the given property name. 
static XPolynomialComplex 
scale(XComplex f,
XPolynomialComplex p)
Returns a new polynomial equivalent mathematically to (f * p), that is, the polynomial obtained by multipying each coefficient of p by the complex scale factor f. 
void 
setCapacity(int capacity)
Sets the capacity of this polynomial to the given value except that any negative value will cause the polynomial storage to be deallocated and the capacity will be 1. 
void 
setCoefficient(int index,
XComplex value)
Sets the coefficient at the given index to a copy of the given value. 
void 
setCoefficients(double[][] params)
Sets the coefficients of the polynomial to a copy of the data in the given params array. 
void 
setCoefficients(float[][] params)
Sets the coefficients of the polynomial to a copy of the data in the given params array. 
void 
setCoefficients(XComplex[] params)
Sets the coefficients of the polynomial to a copy of the data in the given params array. 
void 
setCoefficients(XPolynomialComplex polynomial)
Sets the coefficients of this polynomial to a copy of the data in the given XPolynomialComplex . 
void 
setParam(XComplex[] params)
Sets the coefficients of the polynomial to a copy of the data in the given params array. 
void 
setPolynomialToZero()
Sets the polynomial to the zero polynomial, that is, the polynomial that evaluates to zero everywhere. 
void 
shrinkCapacity()
Sets the capacity to the degree. 
static XPolynomialComplex 
subtract(XPolynomialComplex p,
XPolynomialComplex q)
Returns a new polynomial equivalent mathematically to (p  q). 
double[][] 
toData()
Returns a copy of the polynomial coefficient data as an array of type double[][]. 
String 
toString()
Returns a human readable String representing
the data state of this XPolynomialComplex as an
annotated string. 
String[] 
toStringArrayData()
Returns the data state of this XPolynomialComplex
as an array of strings. 
String 
toStringData()
Returns a human readable String representing
the data state of this XPolynomialComplex as a
simple string. 
Methods inherited from class java.lang.Object 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
Field Detail 
public static final String standardMessage
private static String divisionMessage
protected XComplex[] coefficients
The polynomial coefficients or null
if no
storage has been allocated.
If the coefficients array is nonnull
, it
may nevertheless have null
entries which are
treated as equal to zero. This avoid excess allocation
of complex number storage that may not be used.
protected SwingPropertyChangeSupport changeAdapter
Constructor Detail 
public XPolynomialComplex()
The constructor that sets the polynomial to the zero polynomial but allocates no storage for future coefficients.
public XPolynomialComplex(int capacity)
The constructor that sets the polynomial to the zero polynomial and allocates storage with the given capacity.
capacity
 the desired storage capacitypublic XPolynomialComplex(XComplex[] params)
The constructor that sets the polynomial coefficients to a copy of the given params array.
If params
is null
or of length 0,
sets the polynomial to the zero polynomial
but allocates no storage for future coefficients.
params
 the array of polynomial coefficients to copypublic XPolynomialComplex(double[][] params)
The constructor that sets the polynomial coefficients to a copy of the given params array.
If params
is null
or of length 0,
sets the polynomial to the zero polynomial
but allocates no storage for future coefficients.
params
 the double[][] array of data to copypublic XPolynomialComplex(float[][] params)
The constructor that sets the polynomial coefficients to a copy of the given params array.
If params
is null
or of length 0,
sets the polynomial to the zero polynomial
but allocates no storage for future coefficients.
params
 the float[][] array of data to copypublic XPolynomialComplex(XPolynomialComplex polynomial)
Constructs and initializes an XPolynomialComplex
from
the specified XPolynomialComplex object.
If polynomial
is null
,
sets the polynomial to the zero polynomial
but allocates no storage for future coefficients.
polynomial
 the XPolynomialComplex
object to copypublic XPolynomialComplex(String data) throws ParseException
fromStringData
to set the polynomial coefficients.
public XPolynomialComplex(String[] strings) throws ParseException
fromStringArrayData
to set the polynomial coefficients.
Method Detail 
public void setPolynomialToZero()
Sets the polynomial to the zero polynomial, that is, the polynomial that evaluates to zero everywhere.
Fires property change VALUE.
public int getDegree()
Returns the degree of the polynomial which is defined to be the highest index whose coefficient is nonzero; by convention, the zero polynomial has degree 1.
public int getCapacity()
Returns the capacity of the current internal storage, that is, the largest index into which data may be stored without reallocation of the coefficients array.
Returns 1 if no storage is currently allocated.
public void setCapacity(int capacity)
Sets the capacity of this polynomial to the given value except that any negative value will cause the polynomial storage to be deallocated and the capacity will be 1.
This method does not allocate new storage for
individual complex coefficients since by convention this
class treats a null
coefficient as equal to
zero.
If the capacity is set to a value less than the degree, then information will be lost.
Fires property change VALUE if information is lost due to a call of this method.
capacity
 the desired storage capacitypublic void shrinkCapacity()
Sets the capacity to the degree.
Equivalent to setCapacity(getDegree())
.
public XComplex[] getCoefficients()
Returns a copy of the polynomial coefficients.
Returns an array of size (d+1) where d is the degree.
If the degree is 1, this array is empty but is not
null
.
Uses XComplex.copy
so it is possible that
some items in the array returned are null
.
Note that the internal coefficient capacity is ignored by this method.
public double[][] toData()
Returns a copy of the polynomial coefficient data as an array of type double[][].
Returns an array of size (d+1) where d is the degree.
If the degree is 1, this array is empty but is not
null
.
Uses XComplex.toData
so it is possible that
some items in the array returned are null
.
Note that the internal coefficient capacity is ignored by this method.
public void setCoefficients(XComplex[] params)
Sets the coefficients of the polynomial to a copy of the data in the given params array.
If the given params is null
or of length
0, sets this polynomial to the zero polynomial.
Uses XComplex.copy
to copy the data from
the given params array.
Fires property change VALUE.
params
 the array of polynomial coefficients to copypublic void setCoefficients(double[][] params)
Sets the coefficients of the polynomial to a copy of the data in the given params array.
If the given params is null
or of length
0, sets this polynomial to the zero polynomial.
Uses XComplex.copyData
to copy the data
from the given params array.
Fires property change VALUE.
params
 the double[][] array of data to copypublic void setCoefficients(float[][] params)
Sets the coefficients of the polynomial to a copy of the data in the given params array.
If the given params is null
or of length
0, sets this polynomial to the zero polynomial.
Uses XComplex.copyData
to copy the data
from the given params array.
Fires property change VALUE.
params
 the float[][] array of data to copypublic void setCoefficients(XPolynomialComplex polynomial)
Sets the coefficients of this polynomial to a copy of
the data in the given XPolynomialComplex
.
If the given polynomial is null
, sets this
polynomial to the zero polynomial.
Uses XComplex.copy
to copy the data from
the given polynomial.
Fires property change VALUE.
polynomial
 the XPolynomialComplex
object to copypublic XComplex getCoefficient(int index)
Returns a copy of the coefficient at the given index.
Uses XComplex.copy
.
Returns null
if the index is invalid or the
internal coefficient at the index is null
.
index
 the index of the coefficientpublic void setCoefficient(int index, XComplex value)
Sets the coefficient at the given index to a copy of the given value.
Does nothing if the index is less than zero.
If the index is greater than the capacity, then the capacity is increased to accomodate the index.
Technical note: If several coefficients are to be set via this method, it is most efficient to set the highest index first since that will guarantee enough capacity for all other assignments.
Uses XComplex.copy
.
Fires property change VALUE.
index
 the index of the coefficientvalue
 the value of the coefficientpublic double maxCoefficient()
Returns the maximum of the method maxabs
applied to
the coefficients in this polynomial.
We use maxabs
rather than abs
to avoid
the computation of numerous square roots.
Returns 0 if the polynomial has no nontrivial coefficients.
public boolean isZero()
public boolean isAlmostZero(double epsilon)
Returns true if the polynomial is almost the zero polynomial
relative to the measure epsilon, that is, if all of its
coefficients have a maxabs
value that is less than
or equal to epsilon.
Replaces epsilon with its absolute value before testing.
Remark: If the polynomial has degree d and is almost zero to within epsilon, then for x with absolute value at most one:
abs(evaluate(x)) <= (d + 1) * sqrt(2) * epsilon
In other words, a polynomial that is almost zero to within epsilon has quite small values for arguments x at most one.
The reason for sqrt(2)
in the above estimate is
that we use maxabs
to bound the size of the
coefficients rather than the more expensive abs
;
we also use the relation: abs<=sqrt(2)*maxabs
.
epsilon
 the measure of closeness to zeropublic boolean isEqualTo(XPolynomialComplex p)
Returns true if the given polynomial is equal to this
in the sense that the degrees are the same and all coefficients agree
using XComplex.isEqualTo
to test equality.
If the given polynomial is null
then returns true
if and only if this
equals the zero polynomial.
Ignores polynomial capacity since this is irrelevant as far as testing equality.
p
 a polynomialpublic boolean isAlmostEqualTo(XPolynomialComplex p, double epsilon)
Returns true if the given polynomial is almost equal to this polynomial in the sense that all coefficients agree to within the measure epsilon.
Equivalently, returns true if the difference between this and the given polynomial is almost zero to within the measure epsilon.
If the given polynomial is null
then returns true
if and only if this
is almost zero to within epsilon.
p
 a polynomialepsilon
 the measure of closenesspublic XComplex evaluate(XComplex x)
Returns the value of the polynomial at the given x.
Implements FunctionComplex.OneArg
.
evaluate
in interface FunctionComplex.OneArg
x
 the position at which to evaluate the polynomialpublic void setParam(XComplex[] params)
Sets the coefficients of the polynomial to a copy of the data in the given params array.
Implements ParameterComplex.ArrayParam
.
Equivalent to setCoefficients
.
Fires property change VALUE.
setParam
in interface ParameterComplex.ArrayParam
params
 the array of polynomial coefficients to copypublic String toString()
Returns a human readable String
representing
the data state of this XPolynomialComplex
as an
annotated string.
XPolynomialComplex{c0=[...;...]c1=[...;...]c2=[...;...]etc}
where [...;...] stands for the complex numbers that form the polynomial coefficients in increasing order from left to right.
The zero polynomial is represented as:
XPolynomialComplex{}
public String toStringData()
Returns a human readable String
representing
the data state of this XPolynomialComplex
as a
simple string.
{[...;...][...;...][...;...]etc}
where [...;...] stands for the complex numbers that form the polynomial coefficients in increasing order from left to right.
The zero polynomial is represented as:
{}
toStringData
in interface Stringable
Stringable.fromStringData(String)
public String[] toStringArrayData()
Returns the data state of this XPolynomialComplex
as an array of strings.
This is a convenience method that allows to caller to use the string representations of the individual coefficients in any way desired.
Returns an array of size (d+1) where d is the degree.
If the degree is 1, this array is empty but is not
null
.
public void fromStringData(String data) throws ParseException
Defines the data state for this XPolynomialComplex
object from a String
representation of the data state.
Accepts string data in the format output by toString
or by toStringData
.
Technical note: The parser ignores any labels of the form
ci=
and reads only the coefficient data from
index 0 on up.
The labels if present simply help the user track the index of each coefficient as data is entered. In particular, it is not valid to omit coefficients and depend on the labels to make this clear.
Fires property change VALUE.
fromStringData
in interface Stringable
data
 String
representation of the data state
ParseException
 if the data is malformedStringable.toStringData()
public void fromStringArrayData(String[] strings) throws ParseException
Defines the data state for this XPolynomialComplex
object
from a String
array representation of the data state.
Each string in the array is used to defining the correspoding coefficient in the polynomial.
Technical note: The parser ignores any labels of the form
ci=
and reads only the coefficient data from
index 0 on up.
Fires property change VALUE.
strings
 String
array representation of the data state
ParseException
 if the data is malformedpublic static XPolynomialComplex scale(XComplex f, XPolynomialComplex p)
Returns a new polynomial equivalent mathematically to (f * p), that is, the polynomial obtained by multipying each coefficient of p by the complex scale factor f.
If the polynomial p is null
or the zero polynomial
or if f is null
returns a zero polynomial.
f
 a scale factorp
 a polynomialpublic static XPolynomialComplex add(XPolynomialComplex p, XPolynomialComplex q)
Returns a new polynomial equivalent mathematically to (p + q).
If either polynomial is null
or the zero polynomial
returns a copy of the other polynomial.
p
 a polynomialq
 a polynomialpublic static XPolynomialComplex subtract(XPolynomialComplex p, XPolynomialComplex q)
Returns a new polynomial equivalent mathematically to (p  q).
If polynomial q is null
or the zero polynomial
returns a copy of polynomial p.
If polynomial p is null
or the zero polynomial
returns a copy of the negative of polynomial q.
p
 a polynomialq
 a polynomialpublic static XPolynomialComplex multiply(XPolynomialComplex p, XPolynomialComplex q)
Returns a new polynomial equivalent mathematically to (p * q).
If either polynomial is null
or the zero polynomial
returns a zero polynomial.
p
 a polynomialq
 a polynomialpublic static XPolynomialComplex[] divide(XPolynomialComplex p, XPolynomialComplex q)
Returns a polynomial array consisting of 2 items: the quotient of p divided by q and the remainder of p divided by q.
More precisely, if we let s,t denote the two components of the returned array, then p = s * q + t and degree(t) < degree(q). The equality is correct to within roundoff error.
If the polynomial q is null
or the zero polynomial,
then throws an ArithmeticException with the message:
Division by zero in class XPolynomialComplex
.
Otherwise, if the polynomial p is null
or the zero
polynomial, returns a pair of zero polynomials.
p
 a polynomialq
 a polynomialpublic void addPropertyChangeListener(PropertyChangeListener listener)
listener
 the listener to be registeredpublic void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
propertyName
 the name of the desired propertylistener
 the listener to be registeredpublic void removePropertyChangeListener(PropertyChangeListener listener)
listener
 the listener to be deregisteredpublic void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
propertyName
 the name of the desired propertylistener
 the listener to be deregistered


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 