PRODUCTS
Products Overview
Mathematica
Mathematica Student Edition
Mathematica Home Edition
Wolfram
CDF Player
(free download)
Computable Document Format (CDF)
web
Mathematica
grid
Mathematica
Wolfram
Workbench
Wolfram
SystemModeler
Wolfram
Finance Platform
Mathematica
Add-Ons
Wolfram|Alpha Products
SOLUTIONS
Solutions Overview
Engineering
Aerospace Engineering & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Materials Science
Mechanical Engineering
Operations Research
Optics
Petroleum Engineering
Biotechnology & Medicine
Bioinformatics
Medical Imaging
Finance, Statistics & Business Analysis
Actuarial Sciences
Data Analysis & Mining
Econometrics
Economics
Financial Engineering & Mathematics
Financial Risk Management
Statistics
Software Engineering & Content Delivery
Authoring & Publishing
Interface Development
Software Engineering
Web Development
Science
Astronomy
Biological Sciences
Chemistry
Environmental Sciences
Geosciences
Social & Behavioral Sciences
Design, Arts & Entertainment
Game Design, Special Effects & Generative Art
Education
STEM Education Initiative
Higher Education
Community & Technical College Education
Primary & Secondary Education
Students
Technology
Computable Document Format (CDF)
High-Performance & Parallel Computing (HPC)
See Also: Technology Guide
PURCHASE
Online Store
Other Ways to Buy
Volume & Site Licensing
Contact Sales
Software
Service
Upgrades
Training
Books
Merchandise
SUPPORT
Support Overview
Mathematica
Documentation
Knowledge Base
Learning Center
Technical Services
Community & Forums
Training
Does My Site Have a License?
Wolfram User Portal
COMPANY
About Wolfram Research
News
Events
Wolfram Blog
Partnerships
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
All Sites
Wolfram|Alpha
Demonstrations Project
MathWorld
Integrator
Wolfram Functions Site
Mathematica Journal
Wolfram Media
Wolfram
Tones
Wolfram Science
Stephen Wolfram
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE
DOCUMENTATION CENTER
FOR THE LATEST INFORMATION.
DOCUMENTATION CENTER SEARCH
New to
Mathematica
?
Find your learning path
»
Mathematica
>
Mathematics and Algorithms
>
Matrices and Linear Algebra
>
Matrix-Based Minimization
>
LeastSquares
>
Mathematica
>
Mathematics and Algorithms
>
Graphs & Networks
>
Graph Programming
>
Matrices and Linear Algebra
>
Matrix-Based Minimization
>
LeastSquares
>
Mathematica
>
Visualization and Graphics
>
Graphs & Networks
>
Graph Programming
>
Matrices and Linear Algebra
>
Matrix-Based Minimization
>
LeastSquares
>
BUILT-IN MATHEMATICA SYMBOL
Solving Linear Systems
Tutorials »
|
LinearSolve
PseudoInverse
Fit
LinearModelFit
SingularValueDecomposition
QRDecomposition
CoefficientArrays
DesignMatrix
FindFit
NMinimize
FindMinimum
See Also »
|
Curve Fitting & Approximate Functions
Linear Systems
Matrices and Linear Algebra
Matrix-Based Minimization
Optimization
Signal Processing
New in 6.0: Mathematics & Algorithms
New in 6.0: Matrix & Linear Algebra Functions
New in 6.0: Numerical Data Handling
New in 8.0: Mathematics & Algorithms
More About »
LeastSquares
LeastSquares
finds an
x
that solves the linear least-squares problem for the matrix equation
.
MORE INFORMATION
LeastSquares
gives a vector
x
that minimizes
Norm
.
The vector
x
is uniquely determined by the minimization only if
Length
[
x
]==
MatrixRank
[
m
]
.
The argument
b
can be a matrix, in which case the least-squares minimization is done independently for each column in
b
.
LeastSquares
works on both numerical and symbolic matrices, as well as
SparseArray
objects.
A
Method
option can also be given. Settings for arbitrary-precision numerical matrices include
and
, and for sparse arrays
and
. The default setting of
Automatic
switches between these methods depending on the matrix given.
EXAMPLES
CLOSE ALL
Basic Examples
(1)
Solve a simple least-squares problem:
Solve a simple least-squares problem:
In[1]:=
Out[1]=
Scope
(4)
Use symbolic input:
m
is a 3×4 matrix and
b
is a length-4 vector:
Use exact arithmetic to find a vector
x
that minimizes
:
Use machine arithmetic:
Use 20-digit precision arithmetic:
Solve the least-squares problem for a random complex matrix:
Use a sparse matrix:
Generalizations & Extensions
(1)
b
can be a matrix:
The first column of the
b
matrix is used to generate the first column of the result:
Options
(1)
m
is a 20×20 Hilbert matrix and
b
is a vector such that the solution of
is known:
With the default tolerance, numerical roundoff is limited so errors are distributed:
With
Tolerance
, numerical roundoff can introduce excessive error:
Specifying a higher tolerance will limit roundoff errors at the expense of a larger residual:
Applications
(1)
Here is some data:
Define cubic basis functions centered at
t
with support on the interval
:
Set up a sparse design matrix for basis functions centered at 0, 1, ..., 10:
Solve the least-squares problem:
Properties & Relations
(3)
When
can be solved exactly,
LeastSquares
is equivalent to
LinearSolve
:
m
is a 5×2 matrix and
b
is a length-5 vector:
Solve the least-squares problem:
This is the minimizer of
:
It is also gives the coefficients for the line with least-squares distance to the points:
LeastSquares
gives the parameter estimates for a linear model with normal errors:
LinearModelFit
fits the model and gives additional information about the fitting:
The parameter estimates:
Extract additional results:
SEE ALSO
LinearSolve
PseudoInverse
Fit
LinearModelFit
SingularValueDecomposition
QRDecomposition
CoefficientArrays
DesignMatrix
FindFit
NMinimize
FindMinimum
TUTORIALS
Solving Linear Systems
MORE ABOUT
Curve Fitting & Approximate Functions
Linear Systems
Matrices and Linear Algebra
Matrix-Based Minimization
Optimization
Signal Processing
New in 6.0: Mathematics & Algorithms
New in 6.0: Matrix & Linear Algebra Functions
New in 6.0: Numerical Data Handling
New in 8.0: Mathematics & Algorithms
New in 6