# Linear Least Squares

Solve linear least-squares problems with bounds or linear constraints

Before you begin to solve an optimization problem, you must choose the appropriate approach: problem-based or solver-based. For details, see First Choose Problem-Based or Solver-Based Approach.

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

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 Optimization 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 `optimproblem` Create optimization problem `optimvar` Create optimization variables `solve` Solve optimization problem or equation problem
 `lsqlin` Solve constrained linear least-squares problems `lsqnonneg` Solve nonnegative linear least-squares problem `optim.coder.infbound` Infinite bound support for code generation `mldivide, \` Solve systems of linear equations Ax = B for x `optimwarmstart` Create warm start object

 Optimize Optimize or solve equations in the Live Editor