LeastSquares - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


LinearAlgebra

  

LeastSquares

  

least-squares solution to equations

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

LeastSquares(A, B, opt, t, c, options, meth)

Parameters

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

Description

• 

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 NormA·xB,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](..).

Examples

withLinearAlgebra:

A3,0,4|2,3,4:

b1,2,4:

XLeastSquaresA,b

X35162562125

(1)

VectorNormA·Xb

64125

(2)

AfMatrixA,datatype=float:

bfVectorb,datatype=float:

QR,τQRDecompositionAf,output=NAG:

XfLeastSquaresQR,τ,bf

Xf0.5616000000000000.496000000000000

(3)

E2xy+2=0,mx+ny3=0:

Vx,y:

LeastSquaresE,V

x=2n3m+2n,y=2m+3m+2n

(4)

F1+I,43I,I|3,I,1I:

G0,2I,5|3+4I,0,1+I:

LeastSquaresF,G

69331+137I3318933126I331176331+115I331190331+348I331

(5)

FtHermitianTransposeF:

GtHermitianTransposeG:

LeastSquaresFt,Gt,optimize

243331349I3313633118I33143331+8I33162331+109I3317433192I331263331198I33130331185I331183312I3314833144I331

(6)

N1,2,3|3,4,5|5,6,7:

z1,2,3:

MLeastSquaresN,z,free=c

M1+c32c3c3

(7)

N·M

123

(8)

LeastSquaresN,z,optimize

561316

(9)

NfMatrixN,datatype=float:

zfVectorz,datatype=float:

LeastSquaresNf,zf,method=SVD

0.8333333333333330.333333333333333−0.166666666666666

(10)

U,S,VtSingularValuesNf,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

(11)

LeastSquaresU,S,Vt,zf

0.8333333333333330.333333333333333−0.166666666666666

(12)

See Also

LinearAlgebra[LinearSolve]

LinearAlgebra[Norm]

LinearAlgebra[QRDecomposition]

Matrix

Vector