becker.xtras.grapher
Interface IPolynomialFunction

All Known Implementing Classes:
SamplePolynomialFunction

public interface IPolynomialFunction

A polynomial function, f(x), has a number of terms, each of the form aixi. A polynomial, f, has the form anxn + an-1xn-1 + ... + a1x1 + a0x0 where the coefficients an .. a0 are real numbers. The degree of a polynomial is the value of the largest exponent of x, or n.

For example, if a3=2.0, a2=1.0, a1=0.0, and a0=1.0 then
f(x) = 2.0*x3 + 1.0*x2 + 0.0*x1 - 1.0*x0 or
f(x) = 2.0*x3 + 1.0*x2 - 1.0. The function may be evaluated for a particular value of x by substituting the value for x in the above equation. For example,
f(2) = 2.0*23 + 1.0*22 - 1.0
or 19.

A class implementing the IPolynomialFunction interface will be able to evaluate a function at a particular value of x using the eval method. The current values of the coefficients can be obtained with getCoefficients, and new values can be set with setCoefficients.

A class implementing IPolynomialFunction will begin with the code
public class MyClassName extends Object implements IPolynomialFunction.

The function can be graphed by passing an instance of IPolynomialFunction to GrapherGUI. Please see the package description for a more in-depth discussion of using this class.

Author:
Byron Weber Becker
See Also:
GrapherGUI, IFunction, IQuadraticFunction

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 numVals)
          Get evenly distributed values for f(x) for all the values of x between minX and maxX.
 void setCoefficients(double[] coef)
          Set the coefficients for this polynomial.
 

Method Detail

getDegree

int getDegree()
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.

Returns:
the degree of this polynomial.

setCoefficients

void setCoefficients(double[] coef)
Set the coefficients for this polynomial. The length of the array of coefficients must be equal to the degree + 1.

Parameters:
coef - the coefficients to the polynomial such that ai appears in coef[i].

getCoefficients

double[] getCoefficients()
Get the coefficients for this polynomial. The length of the array of coefficients must be equal to the degree + 1.

Returns:
the coefficients to the polynomial such that ai appears in theith position in the array.

getYValues

double[] getYValues(double minX,
                    double maxX,
                    int numVals)
Get evenly distributed values for f(x) for all the values of x between minX and maxX.

Parameters:
minX - The smallest value of x; must be less than maxX.
maxX - The largest value of x.
numVals - 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)

eval

double eval(double x)
Evaluate the function for a given value of x.

Parameters:
x - The value for which the function should be evaluated.

addView

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