|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object calculator.RatPoly
public final class RatPoly
RatPoly represents an immutable single-variate polynomial expression. RatPolys are sums of RatTerms with non-negative exponents.
Examples of RatPolys include "0", "x-10", and "x^3-2*x^2+5/3*x+3", and "NaN".
Field Summary | |
---|---|
static RatPoly |
NaN
A constant holding a Not-a-Number (NaN) value of type RatPoly |
static RatPoly |
ZERO
A constant holding a zero value of type RatPoly |
Constructor Summary | |
---|---|
RatPoly()
|
|
RatPoly(int c,
int e)
|
|
RatPoly(RatTerm rt)
|
Method Summary | |
---|---|
RatPoly |
add(RatPoly p)
Addition operation. |
RatPoly |
antiDifferentiate(RatNum integrationConstant)
Returns the antiderivative of this RatPoly. |
int |
degree()
Returns the degree of this RatPoly. |
RatPoly |
differentiate()
Return the derivative of this RatPoly. |
RatPoly |
div(RatPoly p)
Division operation (truncating). |
boolean |
equals(java.lang.Object obj)
Standard equality operation. |
double |
eval(double d)
Returns the value of this RatPoly, evaluated at d. |
RatTerm |
getTerm(int deg)
Gets the RatTerm associated with degree 'deg' |
int |
hashCode()
Standard hashCode function. |
double |
integrate(double lowerBound,
double upperBound)
Returns the integral of this RatPoly, integrated from lowerBound to upperBound. |
boolean |
isNaN()
Returns true if this RatPoly is not-a-number. |
RatPoly |
mul(RatPoly p)
Multiplication operation. |
RatPoly |
negate()
Return the additive inverse of this RatPoly. |
RatPoly |
sub(RatPoly p)
Subtraction operation. |
java.lang.String |
toString()
Returns a string representation of this RatPoly. |
static RatPoly |
valueOf(java.lang.String polyStr)
Builds a new RatPoly, given a descriptive String. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final RatPoly NaN
public static final RatPoly ZERO
Constructor Detail |
---|
public RatPoly()
public RatPoly(RatTerm rt)
public RatPoly(int c, int e)
Method Detail |
---|
public int degree()
public RatTerm getTerm(int deg)
public boolean isNaN()
public RatPoly negate()
public RatPoly add(RatPoly p)
public RatPoly sub(RatPoly p)
public RatPoly mul(RatPoly p)
public RatPoly div(RatPoly p)
Division of polynomials is defined as follows: Given two polynomials u and v, with v != "0", we can divide u by v to obtain a quotient polynomial q and a remainder polynomial r satisfying the condition u = "q * v + r", where the degree of r is strictly less than the degree of v, the degree of q is no greater than the degree of u, and r and q have no negative exponents.
For the purposes of this class, the operation "u / v" returns q as defined above.
The following are examples of div's behavior: "x^3-2*x+3" / "3*x^2" = "1/3*x" (with r = "-2*x+3"). "x^2+2*x+15 / 2*x^3" = "0" (with r = "x^2+2*x+15"). "x^3+x-1 / x+1 = x^2-x+2 (with r = "-3").
Note that this truncating behavior is similar to the behavior of integer division on computers.
public RatPoly differentiate()
The derivative of a polynomial is the sum of the derivative of each term.
public RatPoly antiDifferentiate(RatNum integrationConstant)
The antiderivative of a polynomial is the sum of the antiderivative of each term plus some constant.
public double integrate(double lowerBound, double upperBound)
The Fundamental Theorem of Calculus states that the definite integral of f(x) with bounds a to b is F(b) - F(a) where dF/dx = f(x) NOTE: Remember that the lowerBound can be higher than the upperBound.
public double eval(double d)
public java.lang.String toString()
toString
in class java.lang.Object
There is no whitespace in the returned string.
If the polynomial is itself zero, the returned string will just be "0".
If this.isNaN(), then the returned string will be just "NaN"
The string for a non-zero, non-NaN poly is in the form "(-)T(+|-)T(+|-)...", where "(-)" refers to a possible minus sign, if needed, and "(+|-)" refer to either a plus or minus sign, as needed. For each term, T takes the form "C*x^E" or "C*x" where C > 0, UNLESS: (1) the exponent E is zero, in which case T takes the form "C", or (2) the coefficient C is one, in which case T takes the form "x^E" or "x". In cases were both (1) and (2) apply, (1) is used.
Valid example outputs include "x^17-3/2*x^2+1", "-x+1", "-1/2", and "0".
public static RatPoly valueOf(java.lang.String polyStr)
Valid inputs include "0", "x-10", and "x^3-2*x^2+5/3*x+3", and "NaN".
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |