|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math.analysis.polynomials.PolynomialFunction
public class PolynomialFunction
Immutable representation of a real polynomial function with real coefficients.
Horner's Method is used to evaluate the function.
Constructor Summary | |
---|---|
PolynomialFunction(double[] c)
Construct a polynomial with the given coefficients. |
Method Summary | |
---|---|
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 |
protected static double[] |
differentiate(double[] coefficients)
Returns the coefficients of the derivative of the polynomial with the given coefficients. |
boolean |
equals(Object obj)
|
protected static double |
evaluate(double[] coefficients,
double argument)
Uses Horner's Method to evaluate the polynomial with the given coefficients at the argument. |
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. |
String |
toString()
Returns a string representation of the polynomial. |
double |
value(double x)
Compute the value of the function for the given argument. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PolynomialFunction(double[] c)
The constructor makes a copy of the input array and assigns the copy to the coefficients property.
c
- polynomial coefficients
NullPointerException
- if c is null
NoDataException
- if c is emptyMethod Detail |
---|
public 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 computed
UnivariateRealFunction.value(double)
public int degree()
public double[] getCoefficients()
Changes made to the returned copy will not affect the coefficients of the polynomial.
protected static double evaluate(double[] coefficients, double argument)
coefficients
- the coefficients of the polynomial to evaluateargument
- the input value
NoDataException
- if coefficients is empty
NullPointerException
- if coefficients is nullpublic PolynomialFunction add(PolynomialFunction p)
p
- polynomial to add
public PolynomialFunction subtract(PolynomialFunction p)
p
- polynomial to subtract
public PolynomialFunction negate()
public PolynomialFunction multiply(PolynomialFunction p)
p
- polynomial to multiply by
protected static double[] differentiate(double[] coefficients)
coefficients
- the coefficients of the polynomial to differentiate
NoDataException
- if coefficients is empty
NullPointerException
- if coefficients is nullpublic PolynomialFunction polynomialDerivative()
public UnivariateRealFunction derivative()
derivative
in interface DifferentiableUnivariateRealFunction
public 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 Object
public int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |