CurveFitting
LeastSquares
compute a least-squares approximation
Calling Sequence
Parameters
Description
Examples
LeastSquares(xydata, v, opts)
LeastSquares(xdata, ydata, v, opts)
xydata
-
list, Array, DataFrame, or Matrix of the form [[x1,y1], [x2,y2], ..., [xn,yn]]; data points
xdata
list, Array, DataSeries, or Vector of the form [x1, x2, ..., xn]; independent values
ydata
list, Array, DataSeries, or Vector of the form [y1, y2, ..., yn]; dependent values
v
name; independent variable
opts
(optional) one or more equations of the form weight=wlist, curve=f or params=pset
The LeastSquares routine computes a least-squares approximation to the points {x1,y1,x2,y2,...,xn,yn}. A linear function in variable v is returned unless the curve=f option is provided.
The LeastSquares procedure can be called in two ways.
The first form accepts a list, Array, or Matrix, [[x1,y1],[x2,y2],...,[xn,yn]], of data points.
The second form accepts this input data as two lists, two Arrays, or two Vectors. In this form, the first set of data contains the independent values, [x1,x2,...,xn], and the second set of data contains the dependent values, [y1,y2,...,yn]. Each element must be of type algebraic.
The default function that is returned has the form a⁢v+b. A different function to fit the data points can be specified by using the curve=f option. The function f⁡v must be linear in the unknown parameters, though f itself need not be linear. For example, the function a⁢v2+b⁢v+c is acceptable as it is linear in parameters a, b and c.
If the curve=f option is given, the params=pset option can be used, where pset is a set of the unknown parameters. If the params option is not provided, then the unknown parameters are the indeterminates in f different from v.
A weight can be assigned to each data point by using the weight=wlist option, where wlist is a list containing exactly n non-negative values.
If a unique solution cannot be determined from the input data, then a parametrized solution that uses automatically generated parameter names is returned.
More extensive least-squares fitting functionality, including nonlinear fitting, is available in the Statistics package. For more information, see the Statistics/Regression help page.
This function is part of the CurveFitting package, and so it can be used in the form LeastSquares(..) only after executing the command with(CurveFitting). However, it can always be accessed through the long form of the command by using CurveFitting[LeastSquares](..).
with⁡CurveFitting:
LeastSquares⁡0,1,1,2,2,3,3,10,v
−15+14⁢v5
LeastSquares⁡0,1,2,3,1,2,3,10,v,weight=1,1,1,10
−4773+253⁢v73
LeastSquares⁡0,1,3,5,6,2,−1,−3,6,8,v,curve=a⁢v2+b⁢v+c
487273−33091⁢v+1721⁢v2
See Also
Statistics
Statistics/Regression
type/algebraic
Download Help Document