org.faceless.graph.math

## Class Polynomial

• ```public class Polynomial
extends FunctionCurve```

Represents a Polynomial Curve of any degree > 2. A polynomial can be fitted to a `DataCurve` to give a smoother curve, but owing to the nature of polynomial functions this may result in some large "wiggles" in the curve (we suspect this is not the correct mathematical term). Generally the best choice for a curve fitting function is a `Spline` curve.

• ### Constructor Summary

Constructors
Constructor and Description
```Polynomial(int order, double[] x)```
Create a polynomial of the specified order with the specified coefficients.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static Polynomial` `fit(DataCurve d)`
Return a new polynomial that is fitted to the specified data curve within the tolerance set by `setFitTolerance`.
`static Polynomial` ```fit(double[] xvals, double[] yvals)```
Return a new polynomial that is fitted to the specified array of X and Y values within the tolerance set by `setFitTolerance`.
`static Polynomial` ```fit(int order, double[] xvals, double[] yvals)```
Return a new polynomial of the specified order that is fitted to the specified array of X and Y values within the tolerance set by `setFitTolerance`.
`double` `get(double x)`
Return the value of this curve at the specified X position.
`double` ```maxMatchError(double[] xvals, double[] yvals)```
Return the maximum distance from the specified set of X and Y values of this polynomial.
`static void` `setFitTolerance(double v)`
When fitting a polynomial to a curve, the Fit Tolerance is the maximum distance from each point the polynomial can be, as a proportion of the value of the point.
`java.lang.String` `toString()`
• ### Methods inherited from class org.faceless.graph.math.FunctionCurve

`getMax, getMin, point, steps`
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### Polynomial

```public Polynomial(int order,
double[] x)```
Create a polynomial of the specified order with the specified coefficients. For example, passing in the order `2` and the array `[1, 2, 1]` creates a polynomial representing x^2 + 2x + 1
• ### Method Detail

• #### toString

`public java.lang.String toString()`
Overrides:
`toString` in class `java.lang.Object`
• #### get

`public double get(double x)`
Description copied from class: `Curve`
Return the value of this curve at the specified X position. If the curve has no value at this point (i.e. x<curve min or x>curve max) return `Double.NaN`
Specified by:
`get` in class `Curve`
• #### setFitTolerance

`public static void setFitTolerance(double v)`
When fitting a polynomial to a curve, the Fit Tolerance is the maximum distance from each point the polynomial can be, as a proportion of the value of the point. Lower values give more accurate curves but take more time to fit. The default is 0.05.
• #### fit

`public static Polynomial fit(DataCurve d)`
Return a new polynomial that is fitted to the specified data curve within the tolerance set by `setFitTolerance`.
• #### fit

```public static Polynomial fit(double[] xvals,
double[] yvals)```
Return a new polynomial that is fitted to the specified array of X and Y values within the tolerance set by `setFitTolerance`.
• #### fit

```public static Polynomial fit(int order,
double[] xvals,
double[] yvals)```
Return a new polynomial of the specified order that is fitted to the specified array of X and Y values within the tolerance set by `setFitTolerance`.
• #### maxMatchError

```public double maxMatchError(double[] xvals,
double[] yvals)```
Return the maximum distance from the specified set of X and Y values of this polynomial.