The number of iterations in an optimization depends on a solver's stopping criteria. These criteria include several tolerances you can set. Generally, a tolerance is a threshold which, if crossed, stops the iterations of a solver.
Set tolerances and other criteria using optimoptions
as
explained in Set and Change Options.
Tip
Generally set tolerances such as 
You can find the default tolerances in the Optimization App. Some default tolerances differ for different algorithms, so set both the solver and the algorithm.
optimoptions
displays default
tolerances. For example,
options = optimoptions('fmincon')
You can also find the default tolerances in the options section of the solver function reference page.
TolX
is a lower bound on the size
of a step, meaning the norm of (x_{i} – x_{i+1}).
If the solver attempts to take a step that is smaller than TolX
,
the iterations end. TolX
is sometimes used as a relative bound,
meaning iterations end when (x_{i} – x_{i+1}) < TolX
*(1
+ x_{i}),
or a similar relative measure.
For some algorithms, TolFun
is
a lower bound on the change in the value of the objective function
during a step. For those algorithms, if f(x_{i}) – f(x_{i+1}) < TolFun
,
the iterations end. TolFun
is sometimes used as
a relative bound, meaning iterations end when f(x_{i}) – f(x_{i+1}) < TolFun
*(1
+ f(x_{i})),
or a similar relative measure.
Note:

TolCon
is an upper bound on the
magnitude of any constraint functions. If a solver returns a point x with c(x) > TolCon
or ceq(x) > TolCon
,
the solver reports that the constraints are violated at x. TolCon
can
also be a relative bound.
Note:

MaxIter
is a bound on the number
of solver iterations. MaxFunEvals
is a bound on
the number of function evaluations. Iterations and function evaluations
are discussed in Iterations and Function Counts.
There are two other tolerances that apply to particular solvers: TolPCG
and MaxPCGIter
.
These relate to preconditioned conjugate gradient steps. For more
information, see Preconditioned Conjugate Gradient Method.
There are several tolerances that apply only to the fmincon
interiorpoint
algorithm. For more information, see InteriorPoint
Algorithm in fmincon
options
.
There are several tolerances that apply only to intlinprog
.
See Some "Integer" Solutions Are Not Integers and Branch and Bound.