Returns the Line that is the best least squares
fit through the given set of points.
Namespace: Extreme.Mathematics.Curves
Assembly: Extreme.Numerics (Extreme.Numerics)
Syntax
| Visual Basic (Declaration) |
|---|
Public Shared Function LeastSquaresFit ( _ xValues As Double(), _ yValues As Double() _ ) As Line |
| C# |
|---|
public static Line LeastSquaresFit ( double[] xValues, double[] yValues ) |
| C++ |
|---|
public: static Line^ LeastSquaresFit ( array<double>^ xValues, array<double>^ yValues ) |
Parameters
- xValues ()
- An array of numbers containing the X-coordinates of the points.
- yValues ()
- An array of numbers containing the Y-coordinates of the points.
Return Value
A Line that is the least squares fit through the given set of points.
Remarks
The least squares fit of a line through a set
of points is the line that minimizes the sum of the
squares of the residuals. The residuals are the differences
between the predicted and the actual values.
The coordinates of the points are provided in two Double arrays. These must have the same number of elements, or an exception is thrown.
In rare cases, the least squares line is vertical and the slope is infinite.In this case, a DivideByZeroException exception is thrown.
Exceptions
| Exception | Condition |
|---|---|
| ArgumentNullException | xValues is nullNothingnullptr.
-or- yValues is nullNothingnullptr. |
| DimensionMismatchException | The arrays xValues and yValues have different lengths. |
| DivideByZeroException | The least-squares line is vertical. |