LinearAlgebra
LeastSquares
least-squares solution to equations
Calling Sequence
Parameters
Description
Examples
LeastSquares(A, B, opt, t, c, options, meth)
A
-
Matrix, list, or set
B
Matrix, column Vector or set of variables
opt
(optional) equation of the form optimize=true or false; specifies whether to optimize a parametrized solution
t
(optional) equation of the form free = name; base name to use for free variables in parametrized solutions
c
(optional) equation of the form conjugate=true or false; specifies whether to use the Hermitian transpose in the case of non-floating-point data
options
(optional); constructor options for the result object
meth
(optional) equation of the form method = name where name is one of QR or SVD; floating-point method to use
For Matrix A and Vector B, the LeastSquares(A, B) function returns a Vector that best satisfies the equation A . x is approximately equal to B, in the least squares sense. The result that is returned is the Vector x which minimizes Norm⁡A·x−B,2.
If B is a Matrix, then a Matrix is returned where its ith column is the least squares solution to A·x=Bi, where Bi is the ith column of the Matrix B.
Parameter A can also be a set of equations that describe the linear least-squares problem. In this case, B is the set of variables in which the equations in A occur.
The optimize option (opt) determines how the result is returned in the case when the coefficient Matrix is not full rank (so that there are an infinite number of solutions). If given as optimize=true, the solution with the minimal 2-norm is returned.
If the optimize option is omitted (or is given as optimize=false) then in the case of rational data a parametrized solution is returned if the coefficient Matrix is not full rank. In this case, the parametrization uses names based on the symbol given by the option t. If the option t is not provided then an unassigned symbol _t is generated.
The condition optimize=true can be abbreviated as optimize.
The conjugate option (c) specifies whether to use HermitianTranspose instead of Transpose for problems without a complex data type. The default is true. The condition conjugate=true can be abbreviated as conjugate.
For floating-point numeric Matrices a solution is computed by using a singular value decomposition (SVD) method by default.
For nonnumeric data the solution is computed by default using the normal equations. If the method option is supplied as QR then the default method is overridden.
If A is a list, then the elements of the list are taken as the Matrix factors of the Matrix A, due to some prefactorization. These factors are interpreted, uniquely, as follows:
A list of Matrix, Vector[column] items, [QR, tau], is interpreted as the result of calling QRDecomposition with the output='NAG' option (the factors must contain data for a row-dominant Matrix).
A list of Matrix, Matrix items, [Q, R], is interpreted as the result of calling QRDecomposition with the output=['Q', 'R'] option (the factors must contain data for a row-dominant Matrix).
A list of Matrix, Vector[column], Matrix items, [U, S, Vt], is interpreted as the result of calling SingularValues with the output=['U', 'S', 'Vt'] option.
The constructor options provide additional information (readonly, shape, storage, order, datatype, and attributes) to the Vector constructor that builds the result. These options may also be provided in the form outputoptions=[...], where [...] represents a Maple list. If a constructor option is provided in both the calling sequence directly and in an outputoptions option, the latter takes precedence (regardless of the order).
This function is part of the LinearAlgebra package, and so it can be used in the form LeastSquares(..) only after executing the command with(LinearAlgebra). However, it can always be accessed through the long form of the command by using LinearAlgebra[LeastSquares](..).
with⁡LinearAlgebra:
A≔3,0,4|−2,3,4:
b≔1,2,4:
X≔LeastSquares⁡A,b
X≔35162562125
VectorNorm⁡A·X−b
64125
Af≔Matrix⁡A,datatype=float:
bf≔Vector⁡b,datatype=float:
QR,τ≔QRDecomposition⁡Af,output=NAG:
Xf≔LeastSquares⁡QR,τ,bf
Xf≔0.5616000000000000.496000000000000
E≔2⁢x−y+2=0,m⁢x+n⁢y−3=0:
V≔x,y:
LeastSquares⁡E,V
x=−2⁢n−3m+2⁢n,y=2⁢m+3m+2⁢n
F≔1+I,4−3⁢I,−I|3,I,1−I:
G≔0,2⁢I,5|3+4⁢I,0,−1+I:
LeastSquares⁡F,G
−69331+137⁢I33189331−26⁢I331176331+115⁢I331190331+348⁢I331
Ft≔HermitianTranspose⁡F:
Gt≔HermitianTranspose⁡G:
LeastSquares⁡Ft,Gt,optimize
243331−349⁢I33136331−18⁢I331−43331+8⁢I33162331+109⁢I331−74331−92⁢I331263331−198⁢I331−30331−185⁢I331−18331−2⁢I331−48331−44⁢I331
N≔1,2,3|3,4,5|5,6,7:
z≔1,2,3:
M≔LeastSquares⁡N,z,free=c
M≔1+c3−2⁢c3c3
N·M
123
LeastSquares⁡N,z,optimize
5613−16
Nf≔Matrix⁡N,datatype=float:
zf≔Vector⁡z,datatype=float:
LeastSquares⁡Nf,zf,method=SVD
0.8333333333333330.333333333333333−0.166666666666666
U,S,Vt≔SingularValues⁡Nf,output=U,S,Vt
U,S,Vt≔−0.4461721604067700.7964067657995440.408248290463863−0.5686269049445290.0999838802334582−0.816496580927726−0.691081649482289−0.5964390053326260.408248290463863,13.15934799669310.9118992827772002.30803835595325×10−16,−0.277876299012809−0.537141532406176−0.796406765799544−0.869550513644997−0.2116891766191130.4461721604067700.408248290463863−0.8164965809277260.408248290463863
LeastSquares⁡U,S,Vt,zf
See Also
LinearAlgebra[LinearSolve]
LinearAlgebra[Norm]
LinearAlgebra[QRDecomposition]
Matrix
Vector
Download Help Document