public class PolynomialFunction extends java.lang.Object implements DifferentiableUnivariateRealFunction, java.io.Serializable
Horner's Method is used to evaluate the function.
Constructor and Description |
---|
PolynomialFunction(double[] c)
Construct a polynomial with the given coefficients.
|
Modifier and Type | Method and Description |
---|---|
PolynomialFunction |
add(PolynomialFunction p)
Add a polynomial to the instance.
|
int |
degree()
Returns the degree of the polynomial
|
UnivariateRealFunction |
derivative()
Returns the derivative as a UnivariateRealFunction
|
boolean |
equals(java.lang.Object obj) |
double[] |
getCoefficients()
Returns a copy of the coefficients array.
|
int |
hashCode() |
PolynomialFunction |
multiply(PolynomialFunction p)
Multiply the instance by a polynomial.
|
PolynomialFunction |
negate()
Negate the instance.
|
PolynomialFunction |
polynomialDerivative()
Returns the derivative as a PolynomialRealFunction
|
PolynomialFunction |
subtract(PolynomialFunction p)
Subtract a polynomial from the instance.
|
java.lang.String |
toString()
Returns a string representation of the polynomial.
|
double |
value(double x)
Compute the value of the function for the given argument.
|
public PolynomialFunction(double[] c)
The constructor makes a copy of the input array and assigns the copy to the coefficients property.
c
- polynomial coefficientsjava.lang.NullPointerException
- if c is nullNoDataException
- if c is emptypublic double value(double x)
The value returned is
coefficients[n] * x^n + ... + coefficients[1] * x + coefficients[0]
value
in interface UnivariateRealFunction
x
- the argument for which the function value should be computedUnivariateRealFunction.value(double)
public int degree()
public double[] getCoefficients()
Changes made to the returned copy will not affect the coefficients of the polynomial.
public PolynomialFunction add(PolynomialFunction p)
p
- polynomial to addpublic PolynomialFunction subtract(PolynomialFunction p)
p
- polynomial to subtractpublic PolynomialFunction negate()
public PolynomialFunction multiply(PolynomialFunction p)
p
- polynomial to multiply bypublic PolynomialFunction polynomialDerivative()
public UnivariateRealFunction derivative()
derivative
in interface DifferentiableUnivariateRealFunction
public java.lang.String toString()
The representation is user oriented. Terms are displayed lowest
degrees first. The multiplications signs, coefficients equals to
one and null terms are not displayed (except if the polynomial is 0,
in which case the 0 constant term is displayed). Addition of terms
with negative coefficients are replaced by subtraction of terms
with positive coefficients except for the first displayed term
(i.e. we display -3
for a constant negative polynomial,
but 1 - 3 x + x^2
if the negative coefficient is not
the first one displayed).
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
Copyright © 2010 - 2020 Adobe. All Rights Reserved