umontreal.iro.lecuyer.functions
Class Polynomial
- java.lang.Object
-
- umontreal.iro.lecuyer.functions.Polynomial
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, MathFunction, MathFunctionWithDerivative, MathFunctionWithFirstDerivative, MathFunctionWithIntegral
- Direct Known Subclasses:
- LeastSquares, PolInterp
public class Polynomial extends java.lang.Object implements MathFunction, MathFunctionWithFirstDerivative, MathFunctionWithDerivative, MathFunctionWithIntegral, java.io.Serializable, java.lang.Cloneable
Represents a polynomial of degree n in power form. Such a polynomial is of the formp(x) = c0 + c1x + ... + cnxn,where c0,…, cn are the coefficients of the polynomial.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Polynomial(double... coeff)Constructs a new polynomial with coefficients coeff.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Polynomialclone()doublederivative(double x)Computes (or estimates) the first derivative of the function at point x.doublederivative(double x, int n)Computes (or estimates) the nth derivative of the function at point x.PolynomialderivativePolynomial(int n)Returns a polynomial corresponding to the nth derivative of this polynomial.doubleevaluate(double x)Returns the value of the function evaluated at x.doublegetCoefficient(int i)Returns the ith coefficient of the polynomial.double[]getCoefficients()Returns an array containing the coefficients of the polynomial.intgetDegree()Returns the degree of this polynomial.doubleintegral(double a, double b)Computes (or estimates) the integral of the function over the interval [a, b].PolynomialintegralPolynomial(double c)Returns a polynomial representing the integral of this polynomial.voidsetCoefficients(double... coeff)Sets the array of coefficients of this polynomial to coeff.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Polynomial
public Polynomial(double... coeff)
Constructs a new polynomial with coefficients coeff. The value of coeff[i] in this array corresponds to ci.- Parameters:
coeff- the coefficients of the polynomial.- Throws:
java.lang.NullPointerException- if coeff is null.java.lang.IllegalArgumentException- if the length of coeff is 0.
-
-
Method Detail
-
getDegree
public int getDegree()
Returns the degree of this polynomial.- Returns:
- the degree of this polynomial.
-
getCoefficients
public double[] getCoefficients()
Returns an array containing the coefficients of the polynomial.- Returns:
- the array of coefficients.
-
getCoefficient
public double getCoefficient(int i)
Returns the ith coefficient of the polynomial.- Returns:
- the array of coefficients.
-
setCoefficients
public void setCoefficients(double... coeff)
Sets the array of coefficients of this polynomial to coeff.- Parameters:
coeff- the new array of coefficients.- Throws:
java.lang.NullPointerException- if coeff is null.java.lang.IllegalArgumentException- if the length of coeff is 0.
-
evaluate
public double evaluate(double x)
Description copied from interface:MathFunctionReturns the value of the function evaluated at x.- Specified by:
evaluatein interfaceMathFunction- Parameters:
x- value at which the distribution function is evaluated- Returns:
- function evaluated at x
-
derivative
public double derivative(double x)
Description copied from interface:MathFunctionWithFirstDerivativeComputes (or estimates) the first derivative of the function at point x.- Specified by:
derivativein interfaceMathFunctionWithFirstDerivative- Parameters:
x- the point to evaluate the derivative to.- Returns:
- the value of the derivative.
-
derivative
public double derivative(double x, int n)Description copied from interface:MathFunctionWithDerivativeComputes (or estimates) the nth derivative of the function at point x. For n = 0, this returns the result ofevaluate.- Specified by:
derivativein interfaceMathFunctionWithDerivative- Parameters:
x- the point to evaluate the derivate to.n- the order of the derivative.- Returns:
- the resulting derivative.
-
derivativePolynomial
public Polynomial derivativePolynomial(int n)
Returns a polynomial corresponding to the nth derivative of this polynomial.- Parameters:
n- the degree of the derivative.- Returns:
- the derivative.
-
integral
public double integral(double a, double b)Description copied from interface:MathFunctionWithIntegralComputes (or estimates) the integral of the function over the interval [a, b].- Specified by:
integralin interfaceMathFunctionWithIntegral- Parameters:
a- the starting point of the interval.b- the ending point of the interval.- Returns:
- the value of the integral.
-
integralPolynomial
public Polynomial integralPolynomial(double c)
Returns a polynomial representing the integral of this polynomial. This integral is of the form∫p(x)dx = c + c0x +where c is a user-defined constant.
+ ... +
,
- Parameters:
c- the constant for the integral.- Returns:
- the polynomial representing the integral.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
clone
public Polynomial clone()
- Overrides:
clonein classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG