public final class RatPoly
extends java.lang.Object
Examples of RatPolys include "0", "x-10", and "x^3-2*x^2+5/3*x+3", and "NaN".
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)
Truncating division operation.
|
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.
|
public static final RatPoly NaN
public static final RatPoly ZERO
public RatPoly()
public RatPoly(RatTerm rt)
rt
- the single term which the new RatPoly equalspublic RatPoly(int c, int e)
c
- the constant in the term which the new RatPoly equalse
- the exponent in the term which the new RatPoly equalspublic int degree()
public RatTerm getTerm(int deg)
deg
- the degree for which to find the corresponding RatTermpublic boolean isNaN()
public RatPoly negate()
public RatPoly add(RatPoly p)
p
- the other value to be addedpublic RatPoly sub(RatPoly p)
p
- the value to be subtractedpublic RatPoly mul(RatPoly p)
p
- the other value to be multipliedpublic RatPoly div(RatPoly p)
Truncating division gives the number of whole times that the divisor is contained within the dividend. That is, truncating division disregards or discards the remainder. Over the integers, truncating division is sometimes called integer division; for example, 10/3=3, 15/2=7.
Here is a formal way to define truncating division: u/v = q, if there exists some r such that:
Here are examples of truncating division:
p
- the divisorthis / p
. If p = 0 or this.isNaN() or
p.isNaN(), returns some q such that q.isNaN().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
antiderivativeThe 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 integrationupperBound
- the upper bound of integrationpublic double eval(double d)
d
- the value at which to evaluate this polynomialpublic 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 "(+|-)" refers to either a plus or minus
sign. 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.
public static RatPoly valueOf(java.lang.String polyStr)
polyStr
- a string of the format described in the @spec.requires clause.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
obj
- the object to be compared for equality