public class PolynomialFunction
extends java.lang.Object
Horner's Method is used to evaluate the function.
Constructor | Description |
---|---|
PolynomialFunction(double[] c) |
Construct a polynomial with the given coefficients.
|
Modifier and Type | Method | Description |
---|---|---|
int |
degree() |
Returns the degree of the polynomial.
|
boolean |
equals(java.lang.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() |
|
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 coefficients.NullArgumentException
- if c
is null
.NoDataException
- if c
is empty.public double value(double x)
The value returned is
coefficients[n] * x^n + ... + coefficients[1] * x + coefficients[0]
x
- Argument for which the function value should be computed.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
- Coefficients of the polynomial to evaluate.argument
- Input value.NoDataException
- if coefficients
is empty.NullArgumentException
- if coefficients
is null
.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