Class Polynomial
java.lang.Object
dev.nm.analysis.function.rn2r1.AbstractRealScalarFunction
dev.nm.analysis.function.rn2r1.univariate.AbstractUnivariateRealFunction
dev.nm.analysis.function.polynomial.Polynomial
- All Implemented Interfaces:
AbelianGroup<Polynomial>
,Monoid<Polynomial>
,Ring<Polynomial>
,VectorSpace<Polynomial,
,Real> Function<Vector,
,Double> RealScalarFunction
,UnivariateRealFunction
- Direct Known Subclasses:
CauchyPolynomial
,DPolynomial
,QuadraticMonomial
,ScaledPolynomial
public class Polynomial
extends AbstractUnivariateRealFunction
implements Ring<Polynomial>, VectorSpace<Polynomial,Real>
A polynomial is a
UnivariateRealFunction
that represents a finite length expression constructed from variables and constants,
using the operations of addition, subtraction, multiplication, and constant non-negative whole number exponents.
Specifically, it has the form
\[
p(x) = a_0x^n + a_1x^{n-1} + ... + a_{n-1}x + a_n
\]
This implementation is immutable.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.nm.analysis.function.Function
Function.EvaluationException
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Polynomial
a polynomial representing 1static final Polynomial
a polynomial representing 0 -
Constructor Summary
ConstructorsConstructorDescriptionPolynomial
(double... coefficients) Construct a polynomial from an array of coefficients.Polynomial
(Polynomial that) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionadd
(Polynomial that) + : G × G → Gint
degree()
Get the degree of this polynomial.boolean
double
evaluate
(double x) Evaluate this polynomial at x.Evaluate this polynomial at x.Evaluate this polynomial at x.double
getCoefficient
(int i) Get an-i, the coefficient of xn-i.double[]
Get a copy of the polynomial coefficients.Get the normalized version of this polynomial so the leading coefficient is 1.int
hashCode()
minus
(Polynomial that) - : G × G → Gmultiply
(Polynomial that) × : G × G → GONE()
The multiplicative element 1 in the group such that for any elements a in the group, the equation 1 × a = a × 1 = a holds.opposite()
For each a in G, there exists an element b in G such that a + b = b + a = 0.pow
(int n) scaled
(double c) × : F × V → VtoString()
ZERO()
The additive element 0 in the group, such that for all elements a in the group, the equation 0 + a = a + 0 = a holds.Methods inherited from class dev.nm.analysis.function.rn2r1.univariate.AbstractUnivariateRealFunction
evaluate
Methods inherited from class dev.nm.analysis.function.rn2r1.AbstractRealScalarFunction
dimensionOfDomain, dimensionOfRange
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface dev.nm.analysis.function.Function
dimensionOfDomain, dimensionOfRange
-
Field Details
-
ZERO
a polynomial representing 0 -
ONE
a polynomial representing 1
-
-
Constructor Details
-
Polynomial
public Polynomial(double... coefficients) Construct a polynomial from an array of coefficients. The first/0-th entry corresponds to the xn term. The last/n-th entry corresponds to the constant term. The degree of the polynomial is n, the array length minus 1. For example,
creates an instance ofnew Polynomial(1, -2, 3, 2)
Polynomial
representing x3 - 2x2 + 3x + 2.- Parameters:
coefficients
- the polynomial coefficients
-
Polynomial
Copy constructor.- Parameters:
that
- a polynomial
-
-
Method Details
-
degree
public int degree()Get the degree of this polynomial. It is equal to the largest exponent of the variable. For example, x4 + 1 has a degree of 4.- Returns:
- the polynomial degree
-
getCoefficients
public double[] getCoefficients()Get a copy of the polynomial coefficients. In general,coefficients[i]
is the coefficient of xn-i, where n is the polynomial degree. Specifically,coefficients[0]
is the leading coefficient andcoefficients[n]
the constant term.- Returns:
- a copy of the polynomial coefficients
-
getCoefficient
public double getCoefficient(int i) Get an-i, the coefficient of xn-i.- Parameters:
i
- the i-th coefficient in this polynomial, counting from 0- Returns:
- an-i
- See Also:
-
getNormalization
Get the normalized version of this polynomial so the leading coefficient is 1.- Returns:
- a scaled version of the polynomial that has a leading coefficient 1
-
evaluate
Evaluate this polynomial at x.- Parameters:
x
- the argument- Returns:
- p(x)
-
evaluate
public double evaluate(double x) Evaluate this polynomial at x.- Specified by:
evaluate
in interfaceUnivariateRealFunction
- Parameters:
x
- the argument- Returns:
- p(x)
-
evaluate
Evaluate this polynomial at x.- Parameters:
z
- the argument- Returns:
- p(x)
-
add
Description copied from interface:AbelianGroup
+ : G × G → G- Specified by:
add
in interfaceAbelianGroup<Polynomial>
- Parameters:
that
- the object to be added- Returns:
- this + that
-
minus
Description copied from interface:AbelianGroup
- : G × G → G The operation "-" is not in the definition of of an additive group but can be deduced. This function is provided for convenience purpose. It is equivalent to
.this.add(that.opposite())
- Specified by:
minus
in interfaceAbelianGroup<Polynomial>
- Parameters:
that
- the object to be subtracted (subtrahend)- Returns:
- this - that
-
multiply
Description copied from interface:Monoid
× : G × G → G- Specified by:
multiply
in interfaceMonoid<Polynomial>
- Parameters:
that
- the multiplicand- Returns:
- this × that
-
pow
-
scaled
Description copied from interface:VectorSpace
× : F × V → V The result of applying this function to a scalar, c, in F and v in V is denoted cv.- Specified by:
scaled
in interfaceVectorSpace<Polynomial,
Real> - Parameters:
c
- a multiplier- Returns:
- c * this
- See Also:
-
scaled
-
opposite
Description copied from interface:AbelianGroup
For each a in G, there exists an element b in G such that a + b = b + a = 0. That is, it is the object such asthis.add(this.opposite()) == this.ZERO
- Specified by:
opposite
in interfaceAbelianGroup<Polynomial>
- Returns:
- -this, the additive opposite
- See Also:
-
ZERO
Description copied from interface:AbelianGroup
The additive element 0 in the group, such that for all elements a in the group, the equation 0 + a = a + 0 = a holds.- Specified by:
ZERO
in interfaceAbelianGroup<Polynomial>
- Returns:
- 0, the additive identity
-
ONE
Description copied from interface:Monoid
The multiplicative element 1 in the group such that for any elements a in the group, the equation 1 × a = a × 1 = a holds.- Specified by:
ONE
in interfaceMonoid<Polynomial>
- Returns:
- 1
-
toString
-
equals
-
hashCode
public int hashCode()
-