Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.math.analysis
Class PolynomialFunction

    java.lang.Object
      org.apache.commons.math.analysis.PolynomialFunction

All Implemented Interfaces:
  DifferentiableUnivariateRealFunction, Serializable, UnivariateRealFunction

public class PolynomialFunction
extends Object
implements DifferentiableUnivariateRealFunction, Serializable

Immutable representation of a real polynomial function with real coefficients.

Horner's Method is used to evaluate the function.

Version:
  $Revision: 1.12 $ $Date: 2004/07/20 12:55:01 $
See Also:
  Serialized Form

Field Summary
`(package private) static long` | `serialVersionUID` Serializable version identifier

Constructor Summary
`PolynomialFunction(double[] c)` Construct a polynomial with the given coefficients.

Method Summary
`int` | `degree()` Returns the degree of the polynomial
`UnivariateRealFunction` | `derivative()` Returns the derivative as a UnivariateRealFunction
`protected static double[]` | `differentiate(double[] coefficients)` Returns the coefficients of the derivative of the polynomial with the given coefficients.
`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.
`PolynomialFunction` | `polynomialDerivative()` Returns the derivative as a PolynomialRealFunction
`double` | `value(double x)` Compute the value of the function for the given argument.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### serialVersionUID

    static final long serialVersionUID

  Serializable version identifier

  See Also:
    Constant Field Values

Constructor Detail

### PolynomialFunction

    public PolynomialFunction(double[] c)

  Construct a polynomial with the given coefficients. The first element of the coefficients array is the constant term. Higher degree coefficients follow in sequence. The degree of the resulting polynomial is the length of the array minus 1.

  The constructor makes a copy of the input array and assigns the copy to the coefficients property.

Parameters:
  `c` - polynominal coefficients
Throws:
  `NullPointerException` - if c is null
  `IllegalArgumentException` - if c is empty

Method Detail

### value

    public double value(double x)

  Compute the value of the function for the given argument.

  The value returned is
  `coefficients[n] * x^n + ... + coefficients[1] * x + coefficients[0]`

  Specified by:
    `value` in interface `UnivariateRealFunction`
  Parameters:
    `x` - the argument for which the function value should be computed
  Returns:
    the value of the polynomial at the given point
  See Also:
    `UnivariateRealFunction.value(double)`

### degree

    public int degree()

  Returns the degree of the polynomial

  Returns:
    the degree of the polynomial

### getCoefficients

    public double[] getCoefficients()

  Returns a copy of the coefficients array.

  Changes made to the returned copy will not affect the coefficients of the polynomial.

  Returns:
    a fresh copy of the coefficients array

### evaluate

    protected static double evaluate(double[] coefficients,
                                     double argument)

  Uses Horner's Method to evaluate the polynomial with the given coefficients at the argument.

  Parameters:
    `coefficients` - the coefficients of the polynomial to evaluate
    `argument` - the input value
  Returns:
    the value of the polynomial
  Throws:
    `IllegalArgumentException` - if coefficients is empty
    `NullPointerException` - if coefficients is null

### differentiate

    protected static double[] differentiate(double[] coefficients)

  Returns the coefficients of the derivative of the polynomial with the given coefficients.

  Parameters:
    `coefficients` - the coefficients of the polynomial to differentiate
  Returns:
    the coefficients of the derivative or null if coefficients has length 1.
  Throws:
    `IllegalArgumentException` - if coefficients is empty
    `NullPointerException` - if coefficients is null

### polynomialDerivative

    public PolynomialFunction polynomialDerivative()

  Returns the derivative as a PolynomialRealFunction

  Returns:
    the derivative polynomial

### derivative

    public UnivariateRealFunction derivative()

  Returns the derivative as a UnivariateRealFunction

  Specified by:
    `derivative` in interface `DifferentiableUnivariateRealFunction`
  Returns:
    the derivative function

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2004 The Apache Software Foundation. All Rights Reserved.