Optimization Toolbox

Solve linear, quadratic, integer, and nonlinear optimization problems

Optimization Toolbox™ provides functions for finding parameters that minimize or maximize objectives while satisfying constraints. The toolbox includes solvers for linear programming (LP), mixed-integer linear programming (MILP), quadratic programming (QP), nonlinear programming (NLP), constrained linear least squares, nonlinear least squares, and nonlinear equations. You can define your optimization problem with functions and matrices or by specifying variable expressions that reflect the underlying mathematics.

You can use the toolbox solvers to find optimal solutions to continuous and discrete problems, perform tradeoff analyses, and incorporate optimization methods into algorithms and applications. The toolbox lets you perform design optimization tasks, including parameter estimation, component selection, and parameter tuning. It can be used to find optimal solutions in applications such as portfolio optimization, resource allocation, and production planning and scheduling.

Get Started:

Defining Optimization Problems

Model a design or decision problem as an optimization problem. Set design parameters and decisions as optimization variables. Use them in defining an objective function to optimize and use constraints to limit possible variable values.


Transform a problem description into a mathematical form by defining optimization variables, an objective, and constraints, so that it can be solved with optimization techniques.

Problem-Based Optimization

Write the objective and constraints in MATLAB using expressions that reflect the mathematical form. Build these with optimization variables, mathematical operators, matrix operations, and functions of the variables. Apply an automatically selected solver.

Solver-Based Optimization

Write the objective and constraints in MATLAB using functions when nonlinear and coefficient matrices when linear. Build these with MATLAB matrix operations, mathematical operators, and functions. Apply an appropriate solver.

Solving Optimization Problems

Apply a solver to the optimization problem to find an optimal solution: a set of optimization variable values that produce the optimal value of the objective function, if any, and meet the constraints, if any.

Choosing a Solver

Solve using a nonlinear, quadratic, linear, mixed-integer, least-squares, or multiobjective solver depending on the types of objectives and constraints in the optimization problem. The solver is automatically selected in the problem-based approach.

Points evaluated during optimization of a nonlinear function.

Setting Options

Set optimization options to tune the optimization process, for example, to choose the optimization algorithm used by the solver, or to set termination conditions. Set options to monitor and plot optimization solver progress.

Reviewing and Improving Results

Review the optimality measures and iterative display to assess the solution. Use the links in the exit messages to learn more. Improve performance on nonlinear problems by supplying gradients or using parallel computing to estimate gradients.

Monitoring solver progress with the iterative display.

Nonlinear Programming

Solve optimization problems that have a nonlinear objective or are subject to nonlinear constraints.


Apply quasi-Newton, trust-region, or Nelder-Mead Simplex algorithms to solve unconstrained problems. Apply interior-point, sequential-quadratic-programming (SQP), or trust-region-reflective algorithms to solve constrained problems.


Use nonlinear optimization for estimating and tuning parameters, finding optimal designs, computing optimal trajectories, constructing robust portfolios, and other applications where there is a nonlinear relationship between variables.

Linear and Quadratic Programming

Solve optimization problems that have linear or convex quadratic objectives and are subject to linear constraints.

Linear Programming Solvers

Apply dual-simplex or interior-point algorithms to solve linear programs.

Feasible region and optimal solution of a linear program.

Quadratic Programming Solvers

Apply interior-point, active-set, or trust-region-reflective algorithms to solve quadratic programs.

Feasible region and optimal solution of a quadratic program.


Use linear programming on problems such as resource allocation, production planning, blending, and investment planning. Use quadratic programming on problems such as design optimization, portfolio optimization, and control of hydroelectric dams.

Optimal control strategy found with quadratic programming.

Mixed-Integer Linear Programming

Solve optimization problems that have linear objectives subject to linear constraints, with the additional constraint that some or all variables must be integer-valued.


Solve mixed-integer linear programming problems using the branch and bound algorithm, which includes preprocessing, heuristics for generating feasible points, and cutting planes.

Applying the branch and bound algorithm. 

Mixed-Integer Linear Programming-Based Algorithms

Use the mixed-integer linear programming solver to build special-purpose algorithms.

The shortest tour visiting each city only once.


Model with integer variables when there are on/off decisions or logical constraints as well as when variable values must be integral. Routing, scheduling, planning, assignment, and capital budgeting problems are typical applications.

Schedule for two generators under varying electricity prices.

Multiobjective Optimization

Solve optimization problems that have multiple objective functions subject to a set of constraints.


Formulate problems as either goal-attainment or minimax. Use goal-attainment when there are optionally weighted goal values for each of the objectives. Use minimax to minimize the worst-case value of a set of objective functions.

Result of sweeping through objective weights with fgoalattain.


Use multiobjective optimization when tradeoffs are required for two or more conflicting objectives. Examples are weight and strength in structural design and risk and return in portfolio optimization.

Magnitude response for initial and optimized filter coefficients.

Least Squares and Equation Solving

Solve nonlinear least-squares problems and nonlinear systems of equations subject to bound constraints. Solve linear least-squares problems subject to bound and linear constraints.

Comparison of local and global approaches.

Linear Least-Squares Applications

Use linear least-squares solvers to fit a linear model to acquired data or to solve a system of linear equations, including when the parameters are subject to bound and linear constraints.

Recovering a blurred image by solving a linear least-squares problem.

Nonlinear Least-Squares Applications

Use nonlinear least-squares solvers to fit a nonlinear model to acquired data or to solve a system of nonlinear equations, including when the parameters are subject to bound constraints.

Fitting a circular path to the Lorenz system of ordinary differential equations.


Build optimization-based decision support and design tools, integrate with enterprise systems, and deploy optimization algorithms to embedded systems.

MATLAB Compiler Support

Use MATLAB Compiler™ and MATLAB Compiler SDK™ to deploy MATLAB optimization models as standalone executables, web apps, C/C++ shared libraries, Microsoft® .NET assemblies, Java® classes, and Python® packages.

App that computes an optimal power generation schedule.

Code Generation

Generate portable and readable C or C++ code to solve optimization problems using MATLAB CoderTM. Compile the generated code for any hardware, including embedded systems.

MATLAB Coder report for a trajectory optimization function.

Latest Features

Code Generation

Generate C/C++ code to solve quadratic programming problems with quadprog (requires MATLAB Coder) 

Code Generation

Generate C/C++ code to solve nonlinear constrained optimization problems with fmincon (requires MATLAB Coder)

Optimization Modeling

Define nonlinear optimization objective functions or constraints using elementary functions of optimization variables

Quadratic Programming and Linear Least Squares

Solve dense problems quickly and accurately using the active-set algorithm

Mixed-Integer Linear Programming

Obtain feasible points faster with additional heuristics

Infeasibility Analysis Example

Identify conflicting linear constraints by finding irreducible infeasible or maximal feasible subsets

See release notes for details on any of these features and corresponding functions.