Main Content

Nonlinear Least Squares (Curve Fitting)

Solve nonlinear least-squares (curve-fitting) problems in serial or parallel

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.

Nonlinear least-squares solves min(∑||F(xi) - yi||2), where F(xi) is a nonlinear function and yi is data. See Nonlinear Least Squares (Curve Fitting).

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 lsqcurvefit or lsqnonlin.


expand all

evaluateEvaluate optimization expression
infeasibilityConstraint violation at a point
optimproblemCreate optimization problem
optimvarCreate optimization variables
solveSolve optimization problem or equation problem
optim.coder.infboundInfinite bound support for code generation
lsqcurvefitSolve nonlinear curve-fitting (data-fitting) problems in least-squares sense
lsqnonlinSolve nonlinear least-squares (nonlinear data-fitting) problems

Live Editor Tasks

OptimizeOptimize or solve equations in the Live Editor


Problem-Based Nonlinear Least Squares

Solver-Based Nonlinear Least Squares

Code Generation

Parallel Computing

Algorithms and Options