java.lang.Object
org.bzdev.math.RealValuedFunctionVA
org.bzdev.math.RealValuedFunction
org.bzdev.math.BezierPolynomial
- All Implemented Interfaces:
DoubleUnaryOperator
,RealValuedDomainOps
,RealValuedFunctOps
,RealValuedFunctVAOps
,VADomainOps
Class representing polynomials using a Bernstein basis.
Methods include ones for computing a polynomial's value,
obtaining or modifying a polynomial's coefficients,
computing integrals and derivatives of a polynomial, and
adding, multiplying or dividing polynomials.
The class Polynomials
has a series of static methods
that can be used to add, multiply, and divide polynomials.
It also has methods that perform these operations on arrays
representing a polynomial's coefficients. Whether decides to
use the Polynomials
class or the corresponding methods
in this class is dependent more on coding style than anything
else (for addition, multiplication and division, the methods
in this class use the methods in the Polynomials
class).
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.math.RealValuedFunctionVA
RealValuedFunctionVA.Linear
-
Field Summary
Fields inherited from class org.bzdev.math.RealValuedFunction
xFunction
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.BezierPolynomial
(double... coefficients) Constructor specifying coefficients.BezierPolynomial
(double[] coefficients, int degree) Constructor specifying coefficients and a degree.BezierPolynomial
(int degree) Constructor specifying a degree.Constructor based on an existing polynomial. -
Method Summary
Modifier and TypeMethodDescriptionCompute the sum of this polynomial and another polynomial.deriv()
Get a function that computes the first derivative of this real-valued function.double
derivAt
(double x) Evaluate the function's first derivative.divide
(BezierPolynomial p, boolean isQuotient) Divide this polynomial by another polynomial and return either the quotient or the remainder.double[]
Get the coefficients for this polynomial Coefficients are order so that, for a polynomial p(x) = a0B0,n(x) + a1B1,n(x) + ...double[]
Get the array used to store coefficients for this polynomial.int
Get the degree of this polynomial.void
Multiply this polynomial by adding another polynomial to this polynomial.integral()
Integrate a polynomial.double
integralAt
(double x) Evaluated the integral of a polynomial.multiply
(double s) Compute the product of this polynomial and a scalar.Compute the product of this polynomial and another polynomial.void
multiplyBy
(double s) Modify this polynomial by multiplying it by a scalar.void
Modify this polynomial by multiplying it by another polynomial.void
reset
(int degree) Reset this polynomial so that it is empty but with space allocated for polynomials whose degree is no larger than the one specified.Get a function that computes the second derivative of this real-valued function.double
secondDerivAt
(double x) Evaluate the function's second derivative.void
setCoefficients
(double[] coefficients) Set the coefficients for this polynomial.void
setCoefficients
(double[] coefficients, int degree) Set the coefficients of this polynomial, specifying a degree.void
Set the degree and coefficients of this polynomial to match those of a specified polynomial.void
softReset
(int degree) Reset this polynomial so that it is empty.double
valueAt
(double x) Call the function.Methods inherited from class org.bzdev.math.RealValuedFunction
deriv, derivAt, domainMaxClosed, domainMaxClosed, domainMinClosed, domainMinClosed, getDomainMax, getDomainMax, getDomainMin, getDomainMin, isInDomain, isInDomain, secondDerivAt, valueAt
Methods inherited from class org.bzdev.math.RealValuedFunctionVA
jacobian, jacobian, maxArgLength, minArgLength
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.math.RealValuedFunctOps
andThen, andThen, applyAsDouble, compose, compose, maxArgLength, minArgLength
-
Constructor Details
-
BezierPolynomial
public BezierPolynomial()Constructor. -
BezierPolynomial
Constructor based on an existing polynomial.- Parameters:
p
- the existing polynomial
-
BezierPolynomial
public BezierPolynomial(int degree) Constructor specifying a degree. The degree is used to set an internal table size.- Parameters:
degree
- the degree of a polynomial that this instance should support.
-
BezierPolynomial
public BezierPolynomial(double[] coefficients, int degree) Constructor specifying coefficients and a degree. Coefficients are order so that, for a polynomial p(x) = a0B0,n(x) + a1B1,n(x) + ... + anBn,n(x), the coefficient for the Bi,n term is stored in an array at index i, thus making a0 the first index in p's coefficient array (which is newly allocated) The degree is used to set an internal table size.- Parameters:
coefficients
- the coefficients for this polynomial.degree
- the degree of a polynomial that this instance should support.
-
BezierPolynomial
public BezierPolynomial(double... coefficients) Constructor specifying coefficients. Coefficients are order so that, for a polynomial p(x) = a0B0,n(x) + a1B1,n(x) + ... + anBn,n(x), the coefficient for the Bi,n term is stored in an array at index i, thus making a0 the first index in p's coefficient array (which is newly allocated)- Parameters:
coefficients
- the coefficients for this polynomial.
-
-
Method Details
-
setCoefficients
public void setCoefficients(double[] coefficients) Set the coefficients for this polynomial. Coefficients are order so that, for a polynomial p(x) = a0B0,n(x) + a1B1,n(x) + ... + anBn,n(x), the coefficient for the Bi,n term is stored in an array at index i, thus making a0 the first index in p's coefficient array (which is newly allocated)- Parameters:
coefficients
- the coefficients
-
softReset
public void softReset(int degree) Reset this polynomial so that it is empty. If necessary, enough space will be allocated to store the coefficients of a polynomial whose degree is equal to or less than the argument, but the internal array will not be modified unless a new array has to be allocated, and if the array is extended, the old values will be preserved.This method is appropriate when one will set all of the coefficients explicitly or when the old values need to be temporarily preserved (this can happen in cases where the same polynomial is used as two arguments, one of which will be modified).
- Parameters:
degree
- the degree
-
reset
public void reset(int degree) Reset this polynomial so that it is empty but with space allocated for polynomials whose degree is no larger than the one specified. The internal array's elements for indices in the range [0,degree] will be set to zero.- Parameters:
degree
- the degree
-
setTo
Set the degree and coefficients of this polynomial to match those of a specified polynomial.- Parameters:
p
- the specified polynomial
-
setCoefficients
Set the coefficients of this polynomial, specifying a degree. Coefficients are order so that, for a polynomial p(x) = a0B0,n(x) + a1B1,n(x) + ... + anBn,n(x), the coefficient for the Bi,n term is stored in an array at index i, thus making a0 the first index in p's coefficient array (which is newly allocated)- Parameters:
coefficients
- the coefficients (only those indices in the range [0, degree] will be used)degree
- the degree of this polynomial- Throws:
IllegalArgumentException
-
getDegree
public int getDegree()Get the degree of this polynomial.- Returns:
- the degree; -1 if the polynomial is empty (i.e., no coefficients have been provided)
-
getCoefficientsArray
public double[] getCoefficientsArray()Get the array used to store coefficients for this polynomial. The size of the array is guaranteed to be at least 1 larger then the degree of this polynomial. Modifying this array may change the polynomial. Coefficients are order so that, for a polynomial p(x) = a0B0,n(x) + a1B1,n(x) + ... + anBn,n(x), the coefficient for the Bi,n term is stored in an array at index i, thus making a0 the first index in p's coefficient array (which is newly allocated)- Returns:
- the coefficients for this polynomial
-
getCoefficients
public double[] getCoefficients()Get the coefficients for this polynomial Coefficients are order so that, for a polynomial p(x) = a0B0,n(x) + a1B1,n(x) + ... + anBn,n(x), the coefficient for the Bi,n term is stored in an array at index i, thus making a0 the first index in p's coefficient array (which is newly allocated) The size of the array will be the next integer larger than the this polynomial's degree. Modifying the array returned by this method will not change the polynomial.- Returns:
- the coefficients
-
valueAt
public double valueAt(double x) Description copied from class:RealValuedFunction
Call the function.- Specified by:
valueAt
in interfaceRealValuedFunctOps
- Overrides:
valueAt
in classRealValuedFunction
- Parameters:
x
- the function's argument- Returns:
- the value of the function for the given argument
-
integral
Integrate a polynomial. For a polynomial P(x) The integral I(x) = ∫P(x) is implemented so that I(0) = 0. If this polynomial's degree as returned bygetDegree()
is -1, which indicates that the polynomial is not defined, a new polynomial with a degree of -1 will be returned.- Returns:
- the integral of this polynomial
-
integralAt
public double integralAt(double x) Evaluated the integral of a polynomial. For a polynomial P(x) The integral I(x) = ∫P(x) is implemented so that I(0) = 0.- Parameters:
x
- the polynomial's argument- Returns:
- the integral of the polynomial, evaluated at x
-
deriv
Description copied from class:RealValuedFunction
Get a function that computes the first derivative of this real-valued function. If this real-valued function does not support a first derivative, the returned function's valueAt method will throw aUnsupportedOperationException
.- Overrides:
deriv
in classRealValuedFunction
- Returns:
- the first derivative
-
derivAt
public double derivAt(double x) Description copied from class:RealValuedFunction
Evaluate the function's first derivative.- Overrides:
derivAt
in classRealValuedFunction
- Parameters:
x
- the function's argument- Returns:
- the value of the function for the given argument
-
secondDeriv
Description copied from class:RealValuedFunction
Get a function that computes the second derivative of this real-valued function. If this real-valued function does not support a second derivative, the returned function's valueAt method will throw aUnsupportedOperationException
.- Overrides:
secondDeriv
in classRealValuedFunction
- Returns:
- the second derivative
-
secondDerivAt
public double secondDerivAt(double x) Description copied from class:RealValuedFunction
Evaluate the function's second derivative.- Overrides:
secondDerivAt
in classRealValuedFunction
- Parameters:
x
- the function's argument- Returns:
- the value of the function for the given argument
-
incrBy
Multiply this polynomial by adding another polynomial to this polynomial. This polynomial is modified.- Parameters:
p
- the polynomial by which this polynomial is incremented
-
multiplyBy
public void multiplyBy(double s) Modify this polynomial by multiplying it by a scalar. This polynomial is modified.- Parameters:
s
- the scalar
-
multiplyBy
Modify this polynomial by multiplying it by another polynomial. This polynomial is modified.- Parameters:
p
- the polynomial by which this polynomial is multiplied
-
add
Compute the sum of this polynomial and another polynomial. This polynomial is not modified.- Parameters:
p
- the polynomial to add to this polynomial- Returns:
- a new polynomial that is equal to the sum of this polynomial and the polynomial p
-
multiply
Compute the product of this polynomial and another polynomial. This polynomial is not modified.- Parameters:
p
- the polynomial by which this polynomial is multiplied- Returns:
- a new polynomial that is equal to the product of this polynomial and the polynomial p
-
multiply
Compute the product of this polynomial and a scalar. This polynomial is not modified.- Parameters:
s
- the scalar by which this polynomial is multiplied- Returns:
- a new polynomial that is equal to the product of this polynomial and the scalar s
-
divide
Divide this polynomial by another polynomial and return either the quotient or the remainder. This polynomial is not modified. Please seePolynomials.divide(double[],double[],double[],int,double[],int)
for documentation regarding numerical accuracy (this method is used by the implementation of this operation for instances of BezierPolynomial).- Parameters:
p
- the polynomial by which this polynomial is dividedisQuotient
- true if the quotient polynomial is returned; false if the remainder polynomial is returned- Returns:
- a new polynomial whose value is either the quotient or the remainder when this polynomial is divided by the polynomial p
-