test_main

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
 The unconstrained solution is at [1,1]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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