LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
fminsearchbnd_demo.m
1%% Optimization of a simple (Rosenbrock) function, with no constraints
2rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2;
3
4% With no constraints, operation simply passes through
5% directly to fminsearch. The solution should be [1 1]
6xsol = fminsearchbnd(rosen,[3 3])
7
8%% Only lower bound constraints
9xsol = fminsearchbnd(rosen,[3 3],[2 2])
10
11%% Only upper bound constraints
12xsol = fminsearchbnd(rosen,[-5 -5],[],[0 0])
13
14%% Dual constraints
15xsol = fminsearchbnd(rosen,[2.5 2.5],[2 2],[3 3])
16
17%% Mixed constraints
18xsol = fminsearchbnd(rosen,[0 0],[2 -inf],[inf 3])
19
20%% Provide your own fminsearch options
21opts = optimset('fminsearch');
22opts.Display = 'iter';
23opts.TolX = 1.e-12;
24opts.MaxFunEvals = 100;
25
26n = [10,5];
27H = randn(n);
28H=H'*H;
29Quadraticfun = @(x) x*H*x';
30
31% Global minimizer is at [0 0 0 0 0].
32% Set all lower bound constraints, all of which will
33% be active in this test.
34LB = [.5 .5 .5 .5 .5];
35xsol = fminsearchbnd(Quadraticfun,[1 2 3 4 5],LB,[],opts)
36
37%% Exactly fix one variable, constrain some others, and set a tolerance
38opts = optimset('fminsearch');
39opts.TolFun = 1.e-12;
40
41LB = [-inf 2 1 -10];
42UB = [ inf inf 1 inf];
43xsol = fminsearchbnd(@(x) norm(x),[1 3 1 1],LB,UB,opts)
44
45%% All the standard outputs from fminsearch are still returned
46[xsol,fval,exitflag,output] = fminsearchbnd(@(x) norm(x),[1 3 1 1],LB,UB)
47