Mat Lab Opt Toolbox
Mat Lab Opt Toolbox
fminbnd
SYNTAX: x = fminbnd(fun,x1,x2) x = fminbnd(fun,x1,x2,options) x = fminbnd(fun,x1,x2,options,P1,P2,...) (obsolete) [x,fval] = fminbnd(...) [x,fval,exitflag] = fminbnd(...) [x,fval,exitflag,output] = fminbnd(...) fun: m-file, [x1 x2]: options: P1, P2, : built-in function or an inline object. search interval Structure*) of parameters. Set by the optimset function. Parameters needed in and passed on to fun. (obsolete)
ALLOWED OPTIONS: Display off=no output; iter =output at each iteration; final displays just the final output. MaxFunEvals Maximum number of function evaluations allowed. MaxIter Maximum number of iterations allowed. TolX Termination tolerance on x. *) Vector/array of various things
TMA 4180 Optimeringsteori/HEK 2
EXAMPLE: [x,fval,exitflag] =fminbnd('cos',3,4,optimset('TolX',1e-12,'Display','iter')) Function-count 1 2 3 4 5 6 7 8 9 x 3.38197 3.61803 3.23607 3.13571 3.1413 3.14159 3.14159 3.14159 3.14159 f(x) -0.971249 -0.888633 -0.995541 -0.999983 -1 -1 -1 -1 -1 Procedure initial golden golden parabolic parabolic parabolic parabolic parabolic parabolic
Optimization terminated successfully: The current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-012 For a short version of output, use : [x,fval,exitflag,output] =
fminsearch
SYNTAX x = fminsearch(fun,x0) x = fminsearch(fun,x0,options) [x,fval] = fminsearch(...) [x,fval,exitflag] = fminsearch(...) [x,fval,exitflag,output] = fminsearch(...)
OPTIONS structure fields: As for fminbnd + Display TolFun simplex (all corners) Termination tolerance on the function value.
EXAMPLE: [x,fval] = fminsearch('banana', [-1.2, 1] , optimset('TolX',1e-3,'Display','iter')) Iteration Func.-count 1 3 2 5 3 7 4 9 5 11 6 13 7 15 8 16 9 18 10 19 .. 63 119 64 120 65 122 66 124 67 126
TMA 4180 Optimeringsteori/HEK
min f(x) 6.361 4.40994 4.29678 4.29678 4.17987 4.17987 4.17987 4.17987 4.07932 4.07932 2.0633e-007 2.0633e-007 2.0633e-007 2.0633e-007 6.10245e-008
Procedure initial expand expand contract outside contract inside contract outside contract inside reflect expand reflect contract inside reflect contract inside contract inside contract inside
5
optimset
(Type optimset on command line for full info about available options)
SYNTAX:
options = optimset( 'param1' , value1 , 'param2' , value2,...)
options = optimset options = optimset(optimfun) options = optimset(oldopts,'param1',value1,...) options = optimset(oldopts,newopts)
PARAMETERS:
MATLAB AND OPTIMIZATION TOOLBOX:
Display MaxFunEvals MaxIter TolFun TolX [ off | iter | simplex|{final} ] [ positive integer ] [ positive integer ] [ positive scalar ] [ positive scalar ]
lsqnonlin:
Medium size: Gauss/Newton or Levenberg/Marquardt Large size: Trust region methods or Gauss/Newton solved using PCG.
fminunc
Syntax x = fminunc(fun,x0) x = fminunc(fun,x0,options) [x,fval] [x,fval,exitflag] [x,fval,exitflag,output] [x,fval,exitflag,output,grad] [x,fval,exitflag,output,grad,hessian]
OPTIONS:
LargeScale GradObj
10
Example: fminunc
function [f,g] = uncoex(x) f = 3*(x(1)-1)^2 + 2*x(1)*x(2) + x(2)^2; if nargout > 1 g(1) = 6*(x(1)-1)+2*x(2); g(2) = 2*x(1)+2*x(2); end options = optimset('GradObj','on','Display','iter',); x0 = [10,9]; [x,fval] = fminunc('uncoex',x0,options) Norm of step First-order optimality *)
Iteration
f(x)
CG-iterations
1 504 1 72 0 2 23.8973 10 12.5 1 3 -1.5 4.34752 5.33e-015 1 Optimization terminated successfully: First-order optimality less than OPTIONS.TolFun, and no negative/zero curvature detected x = [1.5000 -1.5000] fval = -1.5000
TMA 4180 Optimeringsteori/HEK
lsqnonlin
SYNTAX
x = lsqnonlin(fun,x0) x = lsqnonlin(fun,x0,lb,ub) x = lsqnonlin(fun,x0,lb,ub,options) [x,resnorm] [x,resnorm,residual] [x,resnorm,residual,exitflag] [x,resnorm,residual,exitflag,output] [x,resnorm,residual,exitflag,output,lambda] [x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(...) = lsqnonlin(...) = lsqnonlin(...) = lsqnonlin(...) = lsqnonlin(...) = lsqnonlin(...)
function [F,J] = myfun(x) F = ... % objective function values at x if nargout > 1 % two output arguments J = ... % Jacobian of the function evaluated at x end options = optimset('Jacobian','on')
12
Both the large-scale and medium-scale algorithms: Diagnostics Display Jacobian MaxFunEvals MaxIter TolFun TolX Medium-scale algorithm only: DerivativeChec DiffMaxChange DiffMinChange. LevenbergMarquardt LineSearchType Large-scale algorithm only: JacobPattern MaxPCGIter PrecondBandWidth TolPCG. TypicalX
TMA 4180 Optimeringsteori/HEK 13
Example: lsqnonlin
function F = nonlsqfun(x) k = 1:20; F = 2 + 2*k-exp(k*x(1))-exp(k*x(2)); options = optimset('Display','iter'); x0 = [0.3 0.4]; [x,resnorm] = lsqnonlin('nonlsqfun',x0,[ ],[ ],options) Norm of step 1 0.231124 1.04515 10 2.5 First-order optimality 3.49e+008 1.15e+008 1.77e+007 1.77e+007 1.77e+007 0.0177 0.0177 0.00378
Iter. Func-count f(x) 1 4 2.048e+007 2 7 5.80e+006 3 10 850620 4 13 850620 5 16 850620 -------------------------------------------30 91 1449.48 1.19209e-006 31 94 1449.48 1.19209e-006 32 97 1449.48 2.98023e-007 Optimization terminated successfully: Norm of the current step is less than OPTIONS.TolX x = 0.1652 0.1652 resnorm = 1.4495e+003
TMA 4180 Optimeringsteori/HEK
CG-iterations 0 1 1 1 0 0 1 0
14