fminsearchbnd_demo

PURPOSE ^

% Optimization of a simple (Rosenbrock) function, with no constraints

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% Optimization of a simple (Rosenbrock) function, with no constraints

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Optimization of a simple (Rosenbrock) function, with no constraints
0002 rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2;
0003 
0004 % With no constraints, operation simply passes through
0005 % directly to fminsearch. The solution should be [1 1]
0006 xsol = fminsearchbnd(rosen,[3 3])
0007 
0008 %% Only lower bound constraints
0009 xsol = fminsearchbnd(rosen,[3 3],[2 2])
0010 
0011 %% Only upper bound constraints
0012 xsol = fminsearchbnd(rosen,[-5 -5],[],[0 0])
0013 
0014 %% Dual constraints
0015 xsol = fminsearchbnd(rosen,[2.5 2.5],[2 2],[3 3])
0016 
0017 %% Mixed constraints
0018 xsol = fminsearchbnd(rosen,[0 0],[2 -inf],[inf 3])
0019 
0020 %% Provide your own fminsearch options
0021 opts = optimset('fminsearch');
0022 opts.Display = 'iter';
0023 opts.TolX = 1.e-12;
0024 opts.MaxFunEvals = 100;
0025 
0026 n = [10,5];
0027 H = randn(n);
0028 H=H'*H;
0029 Quadraticfun = @(x) x*H*x';
0030 
0031 % Global minimizer is at [0 0 0 0 0].
0032 % Set all lower bound constraints, all of which will
0033 % be active in this test.
0034 LB = [.5 .5 .5 .5 .5];
0035 xsol = fminsearchbnd(Quadraticfun,[1 2 3 4 5],LB,[],opts)
0036 
0037 %% Exactly fix one variable, constrain some others, and set a tolerance
0038 opts = optimset('fminsearch');
0039 opts.TolFun = 1.e-12;
0040 
0041 LB = [-inf 2 1 -10];
0042 UB = [ inf  inf 1  inf];
0043 xsol = fminsearchbnd(@(x) norm(x),[1 3 1 1],LB,UB,opts)
0044 
0045 %% All the standard outputs from fminsearch are still returned
0046 [xsol,fval,exitflag,output] = fminsearchbnd(@(x) norm(x),[1 3 1 1],LB,UB)
0047

Generated on Thu 10-Dec-2020 17:34:27 by m2html © 2005