Page 240 - Numerical Methods for Chemical Engineering
P. 240
Unconstrained minimizer fminunc in MATLAB 229
Optimization terminated: relative infinity-norm of gradient less than
options.TolFun.
x=1;2
F=0
To let fminunc know that the routine returns the gradient vector, use the ‘GradObj’ field of
optimset,
Options = optimset(‘GradObj’, ‘on’);
[x,F] = fminunc (@simple cost func, x0, Options, ModelParam),
Optimization terminated: first-order optimality less than
OPTIONS. TolFun, and no negative/zero curvature detected in
trust region model.
x=1;2
F=0
To suppress the printing of messages on the screen, use the ‘Display’ field,
Options = optimset(Options, ‘Display’,‘off’);
[x,F] = fminunc (@simple cost func, x0, Options, ModelParam),
x=1;2
F=0
For this problem, the steepest descent method required 58 iterations and the conjugate
gradient method 29. From the additional output arguments,
[x,F,exitflag,output] = fminunc (@simple cost func, . . .
x0, Options, ModelParam),
x=1;2
F=0
exitflag = 1
output =
iterations: 4
funcCount: 5
cgiterations: 4
firstorderopt: 0
algorithm: ‘large-scale: trust-region Newton’
message: [1x137 char]
we see that fminunc was quite efficient at finding the minimum. To avoid using a large-scale
algorithm on this small problem, type
Options = optimset(Options,‘LargeScale’,‘off’);
[x,F,exitflag,output] = fminunc (@simple cost func, x0, Options, ModelParam),
x=1;2
F=0
exitflag = 1
output =