| Genetic Algorithm and Direct Search Toolbox™ | ![]() |
Find unconstrained or bound-constrained minimum of function of several variables using simulated annealing algorithm
x = simulannealbnd(fun,x0)
x = simulannealbnd(fun,x0,lb,ub)
x = simulannealbnd(fun,x0,lb,ub,options)
x = simulannealbnd(problem)
[x,fval] = simulannealbnd(...)
[x,fval,exitflag] = simulannealbnd(...)
[x,fval,exitflag,output] = simulannealbnd(fun,...)
x = simulannealbnd(fun,x0) starts at x0 and finds a local minimum x to the objective function specified by the function handle fun. The objective function accepts input x and returns a scalar function value evaluated at x. x0 may be a scalar or a vector.
x = simulannealbnd(fun,x0,lb,ub) defines a set of lower and upper bounds on the design variables, x, so that a solution is found in the range lb ≤ x ≤ ub. Use empty matrices for lb and ub if no bounds exist. Set lb(i) to -Inf if x(i) is unbounded below; set ub(i) to Inf if x(i) is unbounded above.
x = simulannealbnd(fun,x0,lb,ub,options) minimizes with the default optimization parameters replaced by values in the structure options, which can be created using the saoptimset function. See the saoptimset reference page for details.
x = simulannealbnd(problem) finds the minimum for problem, where problem is a structure containing the following fields:
| objective | Objective function |
| x0 | Initial point of the search |
| lb | Lower bound on x |
| ub | Upper bound on x |
| randstate | Optional field to reset rand state |
| randnstate | Optional field to reset randn state |
| solver | 'simulannealbnd' |
| options | Options structure created using saoptimset |
Create the structure problem by exporting a problem from Optimization Tool, as described in Importing and Exporting Your Work in the Optimization Toolbox™ User's Guide.
[x,fval] = simulannealbnd(...) returns fval, the value of the objective function at x.
[x,fval,exitflag] = simulannealbnd(...) returns exitflag, an integer identifying the reason the algorithm terminated. The following lists the values of exitflag and the corresponding reasons the algorithm terminated:
1 — Average change in the value of the objective function over options.StallIterLimit iterations is less than options.TolFun.
5 — options.ObjectiveLimit limit reached.
0 — Maximum number of function evaluations or iterations exceeded.
-1 — Optimization terminated by the output or plot function.
-2 — No feasible point found.
-5 — Time limit exceeded.
[x,fval,exitflag,output] = simulannealbnd(fun,...) returns output, a structure that contains information about the problem and the performance of the algorithm. The output structure contains the following fields:
problemtype — Type of problem: unconstrained or bound constrained.
iterations — The number of iterations computed.
funccount — The number of evaluations of the objective function.
message — The reason the algorithm terminated.
temperature — Temperature when the solver terminated.
totaltime — Total time for the solver to run.
randstate — The state of rand, the MATLAB® random number generator, just before the algorithm started.
randnstate — The state of randn the MATLAB normal random number generator, just before the algorithm started. You can use the values of randstate and randnstate to reproduce the output of simulannealbnd. See Reproducing Your Results.
Minimization of De Jong's fifth function, a two-dimensional function with many local minima. Enter the command dejong5fcn to generate the following plot.

x0 = [0 0];
[x,fval] = simulannealbnd(@dejong5fcn,x0)
Optimization terminated: change in best function value
less than options.TolFun.
x =
0.0392 -31.9700
fval =
2.9821Minimization of De Jong's fifth function subject to lower and upper bounds:
x0 = [0 0];
lb = [-64 -64];
ub = [64 64];
[x,fval] = simulannealbnd(@dejong5fcn,x0,lb,ub)
Optimization terminated: change in best function value
less than options.TolFun.
x =
-31.9652 -32.0286
fval =
0.9980
The objective can also be an anonymous function:
fun = @(x) 3*sin(x(1))+exp(x(2));
x = simulannealbnd(fun,[1;1],[0 0])
Optimization terminated: change in best function value
less than options.TolFun.
x =
457.1045
0.0000Minimization of De Jong's fifth function while displaying plots:
x0 = [0 0];
options = saoptimset('PlotFcns',{@saplotbestx,...
@saplotbestf,@saplotx,@saplotf});
simulannealbnd(@dejong5fcn,x0,[],[],options)
Optimization terminated: change in best function value
less than options.TolFun.
ans =
0.0230 -31.9806The plots displayed are shown below.

ga, patternsearch, saoptimget, saoptimset, threshacceptbnd
![]() | saoptimset | threshacceptbnd | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |