becker.xtras.grapher
Class SamplePolynomialFunction

java.lang.Object
  extended by becker.xtras.grapher.SamplePolynomialFunction
All Implemented Interfaces:
IPolynomialFunction

public final class SamplePolynomialFunction
extends Object
implements IPolynomialFunction

A sample class implementing the IPolynomialFunction interface. It calculates values of a polynomial function.

Please see the package description for a more in-depth discussion of using this class.

Author:
Byron Weber Becker

Constructor Summary
SamplePolynomialFunction(int deg)
          Create a sample polynomial function with the given degree.
 
Method Summary
 void addView(IView aView)
          Add a view (graphical user interface) to the function.
 double eval(double x)
          Evaluate the function for a given value of x.
 double[] getCoefficients()
          Get the coefficients for this polynomial.
 int getDegree()
          Get the degree of this polynomial.
 double[] getYValues(double minX, double maxX, int num)
          Get evenly distributed values for f(x) for all the values of x between minX and maxX.
 void setCoefficients(double[] coefs)
          Set the coefficients for this polynomial.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SamplePolynomialFunction

public SamplePolynomialFunction(int deg)
Create a sample polynomial function with the given degree.

Parameters:
deg - The degree of the leading term in the polynomial.
Method Detail

eval

public double eval(double x)
Description copied from interface: IPolynomialFunction
Evaluate the function for a given value of x.

Specified by:
eval in interface IPolynomialFunction
Parameters:
x - The value for which the function should be evaluated.

getDegree

public int getDegree()
Description copied from interface: IPolynomialFunction
Get the degree of this polynomial. The degree is the value of the largest exponent of x. For example, the degree of y = 5*x^3 + 2*x^2 + 0*x + 5 is 3.

Specified by:
getDegree in interface IPolynomialFunction
Returns:
the degree of this polynomial.

setCoefficients

public void setCoefficients(double[] coefs)
Description copied from interface: IPolynomialFunction
Set the coefficients for this polynomial. The length of the array of coefficients must be equal to the degree + 1.

Specified by:
setCoefficients in interface IPolynomialFunction
Parameters:
coefs - the coefficients to the polynomial such that ai appears in coef[i].

getCoefficients

public double[] getCoefficients()
Description copied from interface: IPolynomialFunction
Get the coefficients for this polynomial. The length of the array of coefficients must be equal to the degree + 1.

Specified by:
getCoefficients in interface IPolynomialFunction
Returns:
the coefficients to the polynomial such that ai appears in theith position in the array.

getYValues

public double[] getYValues(double minX,
                           double maxX,
                           int num)
Description copied from interface: IPolynomialFunction
Get evenly distributed values for f(x) for all the values of x between minX and maxX.

Specified by:
getYValues in interface IPolynomialFunction
Parameters:
minX - The smallest value of x; must be less than maxX.
maxX - The largest value of x.
num - The number of values to return; must be positive.
Returns:
return an array with f(minX+0*deltaX), f(minX+1*deltaX), f(minX+2*deltaX), ..., f(minX*numVals*deltaX = maxX)

addView

public void addView(IView aView)
Description copied from interface: IPolynomialFunction
Add a view (graphical user interface) to the function. The view's updateView method must be called each time the function's state changes.

Specified by:
addView in interface IPolynomialFunction