|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.math.PolynomialTerm
public class PolynomialTerm
A single term in a polynomial equation of the form f(x)=c0 + c1x + c2x2 + ... + cnxn.
Version Info:
$Revision: 2151 $ |
$Date: 2009-04-03 10:26:17 -0600 (Fri, 03 Apr 2009) $ |
$Author: dharland $ (last person to modify) |
Constructor Summary | |
---|---|
PolynomialTerm()
Creates a new term with a coefficient of 0.0 and an exponent of 0. |
|
PolynomialTerm(double coefficient,
int exponent)
Creates a new term with the given coefficient and exponent. |
Method Summary | |
---|---|
double |
add(PolynomialTerm otherTerm)
Adds otherTerm to this one, if and only if its
exponent is the same as this term's. |
double |
calculateFor(double number)
Returns the value of this term calculated for the given number. |
PolynomialTerm |
clone()
Returns an polynomial term that is equal to this one. |
int |
compareTo(PolynomialTerm otherTerm)
Compares this term with the otherTerm for order. |
PolynomialTerm |
createDerivativeTerm()
Returns a term that is a derivative of this term. |
boolean |
equals(Object o)
Returns true if o is equal to this term. |
double |
getCoefficient()
Returns the coefficient of this term. |
int |
getExponent()
Returns the exponent of this term. |
int |
hashCode()
Returns a hash code value for this term. |
static PolynomialTerm |
parse(String termString)
Returns a new term based on termString . |
void |
set(double newCoefficient,
int newExponent)
Sets both the coefficient and exponent of this term. |
void |
set(String termString)
Returns a new term based on termString . |
void |
setCoefficient(double newCoefficient)
Sets the coefficient of this term to newCoefficient . |
void |
setExponent(int newExponent)
Sets the exponent of this term to newExponent . |
String |
toString()
Returns a string of form #.#t^#. |
String |
toString(char variableName)
Returns a string of form #.#variableName^#. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PolynomialTerm()
public PolynomialTerm(double coefficient, int exponent)
Method Detail |
---|
public void set(double newCoefficient, int newExponent)
newCoefficient
- the new coefficient of this term.newExponent
- the new exponent of this term.public void set(String termString)
termString
.
See parse(String)
for the expected format of
termString
.
termString
- a string that will be used to set this term.
IllegalArgumentException
- if termString
is not in
the expected form.public void setCoefficient(double newCoefficient)
newCoefficient
.
newCoefficient
- the new coefficient of this term.getCoefficient()
public double getCoefficient()
public void setExponent(int newExponent)
newExponent
.
newExponent
- the new exponent of this term.getExponent()
public int getExponent()
i
is the exponent.
public PolynomialTerm createDerivativeTerm()
For the special case where the exponent is zero, the returned
term will have a coefficient of 0.0
and an exponent of
0
.
public double calculateFor(double number)
r = getCoefficient() * (number ^ getExponent())
number
- the value of the independent variable of this term.
For term cixi, x
is the independent variable.
public double add(PolynomialTerm otherTerm)
otherTerm
to this one, if and only if its
exponent is the same as this term's. If the exponents
are not identical, this method does nothing.
otherTerm
- the term to be added to this one.
otherTerm
does not have the same exponent
as this term, the value returned will be the
coefficient of this term before this method was
called.public static PolynomialTerm parse(String termString)
termString
.
The format of termString
is [+-]#.#a^[+-]#,
where
'#' is any numeric character repeated one or more times,
'a' any alpha character [a-zA-Z] repeated one or more times,
'^' is the literal caret character, and
'[+-]'indicates that a '+' character, a '-' character, or neither
is permitted before the coefficient and the exponent.
Examples of typical terms are: 12.34x^56, +12.34x^-56, and -12.34x^+56. Constant terms, such as 42 or 867.5309 are also legal, as are terms that have an implied exponent of one, such as 12.34x.
Special Cases
A termString
of null or "" (the empty
string) will not result in an IllegalArgumentException
,
but will instead return a term whose coefficient and exponent are
both zero.
termString
- a string that will be converted into a polynomial term.
IllegalArgumentException
- if termString
is not in
the expected form.public PolynomialTerm clone()
clone
in class Object
public boolean equals(Object o)
o
is equal to this term.
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(PolynomialTerm otherTerm)
otherTerm
for order.
compareTo
in interface Comparable<PolynomialTerm>
public String toString()
toString
in class Object
public String toString(char variableName)
variableName
- the character to use as the independent variable.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |