 LeastSquares - Maple Help

CurveFitting

 LeastSquares
 compute a least-squares approximation Calling Sequence LeastSquares(xydata, v, opts) LeastSquares(xdata, ydata, v, opts) Parameters

 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 Description

 • The LeastSquares routine computes a least-squares approximation to the points $\left\{\left(\mathrm{x1},\mathrm{y1}\right),\left(\mathrm{x2},\mathrm{y2}\right),...,\left(\mathrm{xn},\mathrm{yn}\right)\right\}$.  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, $[[\mathrm{x1},\mathrm{y1}],[\mathrm{x2},\mathrm{y2}],...,[\mathrm{xn},\mathrm{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, $[\mathrm{x1},\mathrm{x2},...,\mathrm{xn}]$, and the second set of data contains the dependent values, $[\mathrm{y1},\mathrm{y2},...,\mathrm{yn}]$.  Each element must be of type algebraic.
 • The default function that is returned has the form $av+b$.  A different function to fit the data points can be specified by using the curve=f option.  The function $f\left(v\right)$ must be linear in the unknown parameters, though f itself need not be linear. For example, the function $a{v}^{2}+bv+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](..). Examples

 > $\mathrm{with}\left(\mathrm{CurveFitting}\right):$
 > $\mathrm{LeastSquares}\left(\left[\left[0,1\right],\left[1,2\right],\left[2,3\right],\left[3,10\right]\right],v\right)$
 ${-}\frac{{1}}{{5}}{+}\frac{{14}{}{v}}{{5}}$ (1)
 > $\mathrm{LeastSquares}\left(\left[0,1,2,3\right],\left[1,2,3,10\right],v,\mathrm{weight}=\left[1,1,1,10\right]\right)$
 ${-}\frac{{47}}{{73}}{+}\frac{{253}{}{v}}{{73}}$ (2)
 > $\mathrm{LeastSquares}\left(\left[0,1,3,5,6\right],\left[2,-1,-3,6,8\right],v,\mathrm{curve}=a{v}^{2}+bv+c\right)$
 $\frac{{487}}{{273}}{-}\frac{{330}}{{91}}{}{v}{+}\frac{{17}}{{21}}{}{{v}}^{{2}}$ (3)