Package org.faceless.graph.math
Class Polynomial
- java.lang.Object
-
- org.faceless.graph.math.Curve
-
- org.faceless.graph.math.FunctionCurve
-
- org.faceless.graph.math.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 aSpline
curve.
-
-
Constructor Summary
Constructors Constructor Description Polynomial(int order, double[] x)
Create a polynomial of the specified order with the specified coefficients.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 bysetFitTolerance
.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 bysetFitTolerance
.static Polynomial
fit(DataCurve d)
Return a new polynomial that is fitted to the specified data curve within the tolerance set bysetFitTolerance
.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
-
-
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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) returnDouble.NaN
-
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 bysetFitTolerance
.
-
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 bysetFitTolerance
.
-
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 bysetFitTolerance
.
-
maxMatchError
public double maxMatchError(double[] xvals, double[] yvals)
Return the maximum distance from the specified set of X and Y values of this polynomial.
-
-