public class PolynomialFunction extends Object
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 |
---|---|
int |
degree()
Returns the degree of the polynomial.
|
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() |
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.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.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).
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.