Documentation

### This is machine translation

Mouseover text to see original. Click the button below to return to the English version of the page.

# Linear Least Squares

Solve linear least-squares problems with bounds or linear constraints

See First Choose Problem-Based or Solver-Based Approach for choosing between problem-based optimization and solver-based optimization.

Linear least-squares solves min||C*x - d||2, possibly with bounds or linear constraints. See Linear Least Squares.

For the problem-based approach, create problem variables, and then represent the objective function and constraints in terms of these symbolic variables. For the problem-based steps to take, see Problem-Based Workflow. To solve the resulting problem, use `solve`.

For the solver-based steps to take, including defining the objective function and constraints, and choosing the appropriate solver, see Solver-Based Optimization Problem Setup. To solve the resulting problem, use `lsqlin` or, for nonnegative least squares, you can also use `lsqnonneg`.

## Functions

expand all

 `evaluate` Evaluate optimization expression `infeasibility` Constraint violation at a point `solve` Solve optimization problem
 `lsqlin` Solve constrained linear least-squares problems `lsqnonneg` Solve nonnegative linear least-squares problem `mldivide, \` Solve systems of linear equations Ax = B for x

## Topics

### Problem-Based Linear Least Squares Applications

Shortest Distance to a Plane

Shows how to solve a linear least-squares problem using the problem-based approach.

Nonnegative Least-Squares, Problem-Based

Shows how to solve a nonnegative linear least-squares problem using the problem-based approach and several solvers.

Large-Scale Constrained Linear Least-Squares, Problem-Based

Solves an optical deblurring problem using the problem-based approach.

### Solver-Based Linear Least Squares Applications

Optimization App with the lsqlin Solver

Example showing the Optimization app and linear least squares.

Linear Least Squares with Bound Constraints

Example showing the use of bounds in nonlinear least squares.

Jacobian Multiply Function with Linear Least Squares

Example showing how to save memory in a large structured linear least-squares problem.

Large-Scale Constrained Linear Least-Squares, Solver-Based

Solves an optical deblurring problem using the solver-based approach.

### Problem-Based Algorithms

Problem-Based Optimization Algorithms

How the optimization functions and objects solve optimization problems.

Supported Operations on Optimization Variables and Expressions

Lists all available mathematical and indexing operations on optimization variables and expressions.

### Algorithms and Options

Least-Squares (Model Fitting) Algorithms

Minimizing a sum of squares in n dimensions with only bound or linear constraints.

Optimization Options Reference

Describes optimization options.

Watch now