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. The problem can have bounds, linear constraints, or nonlinear 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 lsqcurvefit or lsqnonlin.

Functions

expand all

evaluateEvaluate optimization expression
infeasibilityConstraint violation at a point
optimproblemCreate optimization problem
optimvarCreate optimization variables
solveSolve optimization problem or equation problem
lsqcurvefitSolve nonlinear curve-fitting (data-fitting) problems in least-squares sense
lsqnonlinSolve nonlinear least-squares (nonlinear data-fitting) problems
checkGradientsCheck first derivative function against finite-difference approximation (Since R2023b)
optim.coder.infboundInfinite bound support for code generation (Since R2022b)

Live Editor Tasks

OptimizeOptimize or solve equations in the Live Editor (Since R2020b)

Topics

Problem-Based Nonlinear Least Squares

Solver-Based Nonlinear Least Squares

Code Generation

Parallel Computing

Algorithms and Options