|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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.
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 |
---|
int getDegree()
y = 5*x^3 + 2*x^2 + 0*x + 5
is 3
.
void setCoefficients(double[] coef)
coef
- the coefficients to the polynomial such that ai
appears in coef[i]
.double[] getCoefficients()
double[] getYValues(double minX, double maxX, int numVals)
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.
double eval(double x)
x
- The value for which the function should be evaluated.void addView(IView aView)
updateView
method must be called each time the function's state changes.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |