Inspect the results of an optimization, both while it is running and after it finishes.

Set options to provide iterative display, which gives information on the optimization as the solver runs. Also, set a plot function to show the objective function value as the solver runs.

Set an objective function and start point.

function f = objectivefcn1(x)
f = 0;
for k = -10:10
f = f + exp(-(x(1)-x(2))^2 - 2*x(1)^2)*cos(x(2))*sin(2*x(2));
end

Include the code for `objectivefcn1`

as a file on your MATLAB® path.

Obtain all solver outputs. Use these outputs to inspect the results after the solver finishes.

Iteration Func-count min f(x) Procedure
0 1 -6.70447
1 3 -6.89837 initial simplex
2 5 -7.34101 expand
3 7 -7.91894 expand
4 9 -9.07939 expand
5 11 -10.5047 expand
6 13 -12.4957 expand
7 15 -12.6957 reflect
8 17 -12.8052 contract outside
9 19 -12.8052 contract inside
10 21 -13.0189 expand
11 23 -13.0189 contract inside
12 25 -13.0374 reflect
13 27 -13.122 reflect
14 28 -13.122 reflect
15 29 -13.122 reflect
16 31 -13.122 contract outside
17 33 -13.1279 contract inside
18 35 -13.1279 contract inside
19 37 -13.1296 contract inside
20 39 -13.1301 contract inside
21 41 -13.1305 reflect
22 43 -13.1306 contract inside
23 45 -13.1309 contract inside
24 47 -13.1309 contract inside
25 49 -13.131 reflect
26 51 -13.131 contract inside
27 53 -13.131 contract inside
28 55 -13.131 contract inside
29 57 -13.131 contract outside
30 59 -13.131 contract inside
31 61 -13.131 contract inside
32 63 -13.131 contract inside
33 65 -13.131 contract outside
34 67 -13.131 contract inside
35 69 -13.131 contract inside
Optimization terminated:
the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-04
and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-04
x =
-0.1696 -0.5086
fval =
-13.1310
exitflag =
1
output =
struct with fields:
iterations: 35
funcCount: 69
algorithm: 'Nelder-Mead simplex direct search'
message: 'Optimization terminated:...'

The value of `exitflag`

is `1`

, meaning `fminsearch`

likely converged to a local minimum.

The `output`

structure shows the number of iterations. The iterative display and the plot show this information as well. The `output`

structure also shows the number of function evaluations, which the iterative display shows, but the chosen plot function does not.