least-squares solution to equations
LeastSquares(A, B, opt, t, c, options, meth)
Matrix, list, or set
Matrix, column Vector or set of variables
(optional) equation of the form optimize=true or false; specifies whether to optimize a parametrized solution
(optional) equation of the form free = name; base name to use for free variables in parametrized solutions
(optional) equation of the form conjugate=true or false; specifies whether to use the Hermitian transpose in the case of non-floating-point data
(optional); constructor options for the result object
(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](..).
A ≔ 3,0,4|−2,3,4:
b ≔ 1,2,4:
X ≔ LeastSquares⁡A,b
Af ≔ Matrix⁡A,datatype=float:
bf ≔ Vector⁡b,datatype=float:
QR,τ ≔ QRDecomposition⁡Af,output='NAG':
Xf ≔ LeastSquares⁡QR,τ,bf
E ≔ m⁢x+n⁢y−3=0,2⁢x−y+2=0:
V ≔ x,y:
F ≔ 1+I,4−3⁢I,−I|3,I,1−I:
G ≔ 0,2⁢I,5|3+4⁢I,0,−1+I:
Ft ≔ HermitianTranspose⁡F:
Gt ≔ HermitianTranspose⁡G:
N ≔ 1,2,3|3,4,5|5,6,7:
z ≔ 1,2,3:
M ≔ LeastSquares⁡N,z,free=c
Nf ≔ Matrix⁡N,datatype=float:
zf ≔ Vector⁡z,datatype=float:
U,S,Vt ≔ SingularValues⁡Nf,output='U','S','Vt'
Download Help Document