Class RealUnivariatePolynomial
- All Implemented Interfaces:
IRealFunction,ISmoothRealFunction
- Direct Known Subclasses:
InverseRealPolynomial
Represents a polynomial object with real coefficients over one real variable.
This class is meant more as an encapsulation of a polynomial function rather
than an algebraic object, as is implemented in the JSci
mathematical/science package.
Note that if the zero-argument constructor is used one is essentially left
with a null object. There will be no allocated coefficient
storage until the method is
call. Consequently, any operations called prior to that time will throw a
null pointer exception.
setCoefArray(double[])
- Since:
- Feb 19, 2004
- Version:
- Sep 25, 2015
- Author:
- Christopher Allen
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty polynomial object, the zero polynomial.RealUnivariatePolynomial(double[] arrCoef) Creates and initializes a polynomial to the specified coefficients. -
Method Summary
Modifier and TypeMethodDescriptiondoublederivativeAt(double dblVal) Evaluate the polynomial derivative for the specified value of the indeterminate.doublederivativeAt(int nOrder, double dblLoc) Compute and return the nth derivative at the given location x within the function domain.doubleevaluateAt(double dblVal) Evaluate the polynomial for the specified value of the indeterminate.doublegetCoef(int iOrder) Get the specified coefficient value.double[]getCoefs()Return the entire array of polynomial coefficients.intReturn the degree of the polynomial.static voidTesting driverplus(RealUnivariatePolynomial polyAddend) Nondestructively add two polynomials.voidsetCoefArray(double[] arrCoef) Set the entire coefficient array.times(RealUnivariatePolynomial polyFac) Nondestructive multiply two polynomials.toString()Construct and return a textual representation of the contents of this polynomial as aStringobject.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface xal.tools.math.fnc.IRealFunction
getDomain
-
Constructor Details
-
RealUnivariatePolynomial
public RealUnivariatePolynomial()Creates an empty polynomial object, the zero polynomial. -
RealUnivariatePolynomial
public RealUnivariatePolynomial(double[] arrCoef) Creates and initializes a polynomial to the specified coefficients.- Parameters:
arrCoef-
-
-
Method Details
-
setCoefArray
public void setCoefArray(double[] arrCoef) Set the entire coefficient array. The coefficient array is arranged in order of ascending indeterminate order.- Parameters:
arrCoef- double array of coefficients.
-
getDegree
public int getDegree()Return the degree of the polynomial. That is, the highest indeterminant order for all the nonzero coefficients. -
getCoef
public double getCoef(int iOrder) Get the specified coefficient value. The value of parameteriOrderspecifies order of the indeterminate. For example, callinggetCoef(2)would return the coefficient for the indeterminate of second order. If the value ofiOrderis larger than the size of the coefficient array then the coefficient is assumed to have value zero.- Parameters:
iOrder- order of the indeterminate- Returns:
- coefficient of the specified indeterminate order
-
getCoefs
public double[] getCoefs()Return the entire array of polynomial coefficients. The coefficient array is arranged in order of ascending indeterminate order.- Returns:
- the entire coefficient array
-
evaluateAt
public double evaluateAt(double dblVal) Evaluate the polynomial for the specified value of the indeterminate. If the coefficient vector has not been specified this method returns zero.- Specified by:
evaluateAtin interfaceIRealFunction- Parameters:
dblVal- indeterminate value to evaluate the polynomial- Returns:
- the value of the function at the given location
-
derivativeAt
public double derivativeAt(double dblVal) Evaluate the polynomial derivative for the specified value of the indeterminate. If the coefficient vector has not been specified this method returns zero. Note that the result has one less order of accuracy than the underlying polynomial.- Specified by:
derivativeAtin interfaceISmoothRealFunction- Parameters:
dblVal- indeterminate value to evaluate the polynomial- Returns:
- the derivative f'(x) of the function f
-
derivativeAt
Description copied from interface:ISmoothRealFunctionCompute and return the nth derivative at the given location x within the function domain. The order argument n must be 0 or greater where the 0th derivative is simply the value of the function itself.
It is possible that the derivatives of a function are all zero for n greater than a certain value. Consider a polynomial for example, when n is greater than the degree of that polynomial.
- Specified by:
derivativeAtin interfaceISmoothRealFunction- Parameters:
nOrder- the order n of the derivativedblLoc- the location x at which to evaluate the derivative- Returns:
- the derivative f(n)(x) of the function
- Throws:
IllegalArgumentException- the derivative order must be positive.- Since:
- Sep 25, 2015 by Christopher K. Allen
- See Also:
-
plus
Nondestructively add two polynomials. The current polynomial and the argument are added according to standard definitions (i.e., the coefficient array is added vectorially).- Parameters:
polyAddend- polynomial to be added to this- Returns:
- a new polynomial object representing the sum
-
times
Nondestructive multiply two polynomials. The current polynomial and the argument are multiplied according to standard definitions.- Parameters:
polyFac- polynomial to be multiplied by this- Returns:
- a new polynomial object representing the product
-
toString
Construct and return a textual representation of the contents of this polynomial as aStringobject. -
main
Testing driver
-