umontreal.iro.lecuyer.functionfit
Class LeastSquares
- java.lang.Object
-
- umontreal.iro.lecuyer.functions.Polynomial
-
- umontreal.iro.lecuyer.functionfit.LeastSquares
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, MathFunction, MathFunctionWithDerivative, MathFunctionWithFirstDerivative, MathFunctionWithIntegral
public class LeastSquares extends Polynomial implements java.io.Serializable
Represents a polynomial obtained by the least squares method on a set of points. More specifically, let (x0, y0),…,(xn, yn) be a set of points and p(x) the constructed polynomial of degree m. The constructed polynomial minimizes the square errorE2 = ∑i=0n[yi - p(xi)]2.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description LeastSquares(double[] x, double[] y, int degree)Constructs a new least squares polynomial with points (x[0], y[0]),..., (x[n], y[n]).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description LeastSquaresclone()static double[]getCoefficients(double[] x, double[] y, int degree)Computes and returns the coefficients of the fitting polynomial of degree degree.double[]getX()Returns the x coordinates of the fitted points.double[]getY()Returns the y coordinates of the fitted points.java.lang.StringtoString()CallstoStringwith the associated points.-
Methods inherited from class umontreal.iro.lecuyer.functions.Polynomial
derivative, derivative, derivativePolynomial, evaluate, getCoefficient, getCoefficients, getDegree, integral, integralPolynomial, setCoefficients
-
-
-
-
Constructor Detail
-
LeastSquares
public LeastSquares(double[] x, double[] y, int degree)Constructs a new least squares polynomial with points (x[0], y[0]),..., (x[n], y[n]). The constructed polynomial has degree degree.- Parameters:
x- the x coordinates of the points.y- the y coordinates of the points.degree- the degree of the polynomial.- Throws:
java.lang.NullPointerException- if x or y are null.java.lang.IllegalArgumentException- if the lengths of x and y are different, or if less than degree + 1 points are specified.
-
-
Method Detail
-
getCoefficients
public static double[] getCoefficients(double[] x, double[] y, int degree)Computes and returns the coefficients of the fitting polynomial of degree degree. The coordinates of the given points are (x[i], y[i]).- Parameters:
x- the x coordinates of the points.y- the y coordinates of the points.degree- the degree of the polynomial.- Returns:
- the coefficients of the fitting polynomial.
-
getX
public double[] getX()
Returns the x coordinates of the fitted points.- Returns:
- the x coordinates of the fitted points.
-
getY
public double[] getY()
Returns the y coordinates of the fitted points.- Returns:
- the y coordinates of the fitted points.
-
toString
public java.lang.String toString()
CallstoStringwith the associated points.- Overrides:
toStringin classPolynomial- Returns:
- a string containing the points.
-
clone
public LeastSquares clone()
- Overrides:
clonein classPolynomial
-
-
DMelt 3.0 © DataMelt by jWork.ORG