SSJ
V. 2.2.

umontreal.iro.lecuyer.functionfit
Class LeastSquares

java.lang.Object
  extended by umontreal.iro.lecuyer.functions.Polynomial
      extended by umontreal.iro.lecuyer.functionfit.LeastSquares
All Implemented Interfaces:
Serializable, Cloneable, MathFunction, MathFunctionWithDerivative, MathFunctionWithFirstDerivative, MathFunctionWithIntegral

public class LeastSquares
extends Polynomial
implements 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 error

E2 = ∑i=0n[yi - p(xi)]2.

See Also:
Serialized Form

Constructor Summary
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
 LeastSquares clone()
           
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.
 String toString()
          Calls toString with the associated points.
 
Methods inherited from class umontreal.iro.lecuyer.functions.Polynomial
derivative, derivative, derivativePolynomial, evaluate, getCoefficient, getCoefficients, getDegree, integral, integralPolynomial, setCoefficients
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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:
NullPointerException - if x or y are null.
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 String toString()
Calls toString with the associated points.

Overrides:
toString in class Polynomial
Returns:
a string containing the points.

clone

public LeastSquares clone()
Overrides:
clone in class Polynomial

SSJ
V. 2.2.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.