JIDE 3.5.15

com.jidesoft.chart.fit
Class Polynomial

java.lang.Object
  extended by com.jidesoft.chart.fit.Polynomial

public class Polynomial
extends Object

This class represents a polynomial of any number of terms (provided the powers of x are all positive integers).

So, for example an instance of this class can be used to represent an expression such as x - 5 or 3x2 + 4x + 2


Constructor Summary
Polynomial(double... coefficients)
          Create a polynomial using the supplied coefficients for successive powers of x starting from a constant.
Polynomial(Double[] coefficients)
          Create a polynomial using the supplied coefficients for successive powers of x starting from a constant.
 
Method Summary
 boolean equals(Object obj)
           
 double eval(double x)
          Compute the value of the polynomial for a given x value.
 Double getCoefficient(int index)
          Returns the coefficient of the polynomial with the given index.
 List<Double> getCoefficients()
          Returns the coefficients of the polynomials, lowest term (i.e.
 int hashCode()
           
 void setCoefficients(Double[] coefficients)
          Specify the coefficients of the polynomial
 void setCoefficients(List<Double> coefficients)
          Specify the coefficients of the polynomial
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Polynomial

public Polynomial(Double[] coefficients)
Create a polynomial using the supplied coefficients for successive powers of x starting from a constant. Therefore for 2x+4, supply the arguments [4, 2].

Parameters:
coefficients - the coefficients of the successive terms of the polynomial

Polynomial

public Polynomial(double... coefficients)
Create a polynomial using the supplied coefficients for successive powers of x starting from a constant. Therefore for 2x+4, create as new Polynomial(4, 2).

Parameters:
coefficients - the coefficients of the successive terms of the polynomial
Method Detail

getCoefficients

public List<Double> getCoefficients()
Returns the coefficients of the polynomials, lowest term (i.e. the constant) first

Returns:
the coefficients of the polynomial

getCoefficient

public Double getCoefficient(int index)
Returns the coefficient of the polynomial with the given index. The constant has index of 0.

Parameters:
index - the index of the coefficient; the constant term has zero index.
Returns:
the coefficient of the term indicated

setCoefficients

public void setCoefficients(List<Double> coefficients)
Specify the coefficients of the polynomial

Parameters:
coefficients - the coefficients, given as a List of Doubles

setCoefficients

public void setCoefficients(Double[] coefficients)
Specify the coefficients of the polynomial

Parameters:
coefficients - the coefficients, given as an array of Doubles

eval

public double eval(double x)
Compute the value of the polynomial for a given x value. This works by starting at the coefficient of the highest order term and iteratively multiplying by x and adding the coefficient of the next lower term.

Parameters:
x - the x value to plug into the expression
Returns:
the value of the polynomial for the given x value.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

JIDE 3.5.15