Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
RatPoly() |
RatPoly(int c,
int e) |
RatPoly(RatTerm rt) |
Modifier and Type | Method and Description |
---|---|
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(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.
|
String |
toString()
Returns a string representation of this RatPoly.
|
static RatPoly |
valueOf(String polyStr)
Builds a new RatPoly, given a descriptive String.
|
public RatPoly()
public RatPoly(RatTerm rt)
rt
- The single term which the new RatPoly equals.public RatPoly(int c, int e)
c
- The constant in the term which the new RatPoly equals.e
- The exponent in the term which the new RatPoly equals.public int degree()
public RatTerm getTerm(int deg)
deg
- The degree for which to find the corresponding RatTerm.public boolean isNaN()
public RatPoly negate()
public RatPoly add(RatPoly p)
p
- The other value to be added.public RatPoly sub(RatPoly p)
p
- The value to be subtracted.public RatPoly mul(RatPoly p)
p
- The other value to be multiplied.public RatPoly div(RatPoly p)
p
- The divisor.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)
integrationConstant
- The constant of integration to use when
computating the antiderivative.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.
lowerBound
- The lower bound of integration.upperBound
- The upper bound of integration.public double eval(double d)
d
- The value at which to evaluate this polynomial.public String toString()
toString
in class 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(String polyStr)
polyStr
- A string of the format described in the @requires clause.Valid inputs include "0", "x-10", and "x^3-2*x^2+5/3*x+3", and "NaN".
public int hashCode()