Class RealUnivariatePolynomial

java.lang.Object
xal.tools.math.fnc.poly.RealUnivariatePolynomial
All Implemented Interfaces:
IRealFunction, ISmoothRealFunction
Direct Known Subclasses:
InverseRealPolynomial

public class RealUnivariatePolynomial extends Object implements ISmoothRealFunction

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 setCoefArray(double[]) method is call. Consequently, any operations called prior to that time will throw a null pointer exception.

Since:
Feb 19, 2004
Version:
Sep 25, 2015
Author:
Christopher Allen
  • 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 parameter iOrder specifies order of the indeterminate. For example, calling getCoef(2) would return the coefficient for the indeterminate of second order. If the value of iOrder is 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:
      evaluateAt in interface IRealFunction
      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:
      derivativeAt in interface ISmoothRealFunction
      Parameters:
      dblVal - indeterminate value to evaluate the polynomial
      Returns:
      the derivative f'(x) of the function f
    • derivativeAt

      public double derivativeAt(int nOrder, double dblLoc) throws IllegalArgumentException
      Description copied from interface: ISmoothRealFunction

      Compute 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:
      derivativeAt in interface ISmoothRealFunction
      Parameters:
      nOrder - the order n of the derivative
      dblLoc - 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

      public String toString()
      Construct and return a textual representation of the contents of this polynomial as a String object.
      Overrides:
      toString in class Object
      Returns:
      a String representation of the polynomial contents
      See Also:
    • main

      public static void main(String[] args)
      Testing driver