 linalg(deprecated)/leastsqrs - Maple Help

Home : Support : Online Help : linalg(deprecated)/leastsqrs

linalg(deprecated)

 leastsqrs
 least-squares solution of equations Calling Sequence leastsqrs(A, b) leastsqrs(S, v) Parameters

 A - matrix b - vector S - set of equations or expressions v - set of names Description

 • Important: The linalg package has been deprecated. Use the superseding command LinearAlgebra[LeastSquares], instead.
 - For information on migrating linalg code to the new packages, see examples/LinearAlgebraMigration.
 • The call leastsqrs(A, b) returns the vector that best satisfies $Ax=b$ in the least-squares sense. The result returned is the vector x which minimizes $\mathrm{norm}\left(Ax-b,2\right)$.
 • The call leastsqrs(S, v) finds the values for the variables in v which minimize the equations or expressions in S in the least-squares sense. The result returned is a set of equations whose left-hand sides are from v.
 • For the linear case, if the third optional argument is 'optimize', the routine will find the optimal least square solution (i.e. the vector x with $\mathrm{norm}\left(x,2\right)$ being the smallest). At present, the matrix entries must be rationals.
 • The command with(linalg,leastsqrs) allows the use of the abbreviated form of this command. Examples

Important: The linalg package has been deprecated. Use the superseding command LinearAlgebra[LeastSquares], instead.

 > $\mathrm{with}\left(\mathrm{linalg}\right):$
 > $A≔\mathrm{array}\left(\left[\left[1,1,1\right],\left[1,2,4\right],\left[1,0,0\right],\left[1,-1,1\right]\right]\right)$
 ${A}{≔}\left[\begin{array}{ccc}{1}& {1}& {1}\\ {1}& {2}& {4}\\ {1}& {0}& {0}\\ {1}& {-1}& {1}\end{array}\right]$ (1)
 > $b≔\mathrm{array}\left(\left[3,10,3,\frac{9}{10}\right]\right)$
 ${b}{≔}\left[\begin{array}{cccc}{3}& {10}& {3}& \frac{{9}}{{10}}\end{array}\right]$ (2)
 > $\mathrm{leastsqrs}\left(A,b\right)$
 $\left[\begin{array}{ccc}\frac{{327}}{{200}}& \frac{{301}}{{200}}& \frac{{49}}{{40}}\end{array}\right]$ (3)
 > $S≔\left\{\mathrm{c0}-\frac{9}{10},\mathrm{c0}+\mathrm{c1}+\mathrm{c2}-3,\mathrm{c0}+2\mathrm{c1}+4\mathrm{c2}-10,\mathrm{c0}-\mathrm{c1}+\mathrm{c2}-3\right\}$
 ${S}{≔}\left\{{\mathrm{c0}}{-}\frac{{9}}{{10}}{,}{\mathrm{c0}}{-}{\mathrm{c1}}{+}{\mathrm{c2}}{-}{3}{,}{\mathrm{c0}}{+}{\mathrm{c1}}{+}{\mathrm{c2}}{-}{3}{,}{\mathrm{c0}}{+}{2}{}{\mathrm{c1}}{+}{4}{}{\mathrm{c2}}{-}{10}\right\}$ (4)
 > $\mathrm{leastsqrs}\left(S,\left\{\mathrm{c0},\mathrm{c1},\mathrm{c2}\right\}\right)$
 $\left\{{\mathrm{c0}}{=}\frac{{159}}{{200}}{,}{\mathrm{c1}}{=}\frac{{7}}{{200}}{,}{\mathrm{c2}}{=}\frac{{91}}{{40}}\right\}$ (5)
 > $A≔\mathrm{array}\left(\left[\left[1,-1,1\right],\left[1,1,-2\right],\left[2,0,-1\right]\right]\right):$
 > $b≔\mathrm{vector}\left(\left[1,2,4\right]\right):$
 > $\mathrm{leastsqrs}\left(A,b\right)$
 $\left[\begin{array}{ccc}{{\mathrm{_t}}}_{{1}}& {-}{5}{+}{3}{}{{\mathrm{_t}}}_{{1}}& {2}{}{{\mathrm{_t}}}_{{1}}{-}\frac{{11}}{{3}}\end{array}\right]$ (6)
 > $\mathrm{leastsqrs}\left(A,b,'\mathrm{optimize}'\right)$
 $\left[\begin{array}{ccc}\frac{{67}}{{42}}& {-}\frac{{3}}{{14}}& {-}\frac{{10}}{{21}}\end{array}\right]$ (7)