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