How do I plot the output of fmincon when I'm already using options twice; once to include gradient using optimoptions and the next to plot using optiset?

1 view (last 30 days)
So as said in the question, I have to define options twice but I can't use them concurrently. How can I prevent conflict between include gradient and the output function? Note, that I'm using Matlab 2015 and that one of the options is commented out. Thanks!
resdof=[1,2,12];
dof=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22];
freedof=setdiff(dof,resdof);
ndof=[1,7,7,8,2,7,1,2,2,8,2,3,8,9,3,8,3,4,3,9,9,10,4,9,4,5,4,10,10,11,5,10,5,6,5,11,6,11];
ndof=[1,7,7,8,2,7,1,2,2,8,2,3,8,9,3,8,3,4,3,9,9,10,4,9,4,5,4,10,10,11,5,10,5,6,5,11,6,11];
Lvec=zeros(1,22);
Lvec(1,6)=1;
dfdu=Lvec(freedof);
x0=0.0005*ones(1,19);
lb=zeros(1,19);
options =optimoptions('fmincon','GradObj','on');
%options=optimset('OutputFcn',@outfun);
[x,fval,optimValues.iteration,iterations]=fmincon(@objfun,x0,[],[],[],[],lb,[],@nlcon,options)

Accepted Answer

Alan Weiss
Alan Weiss on 21 Mar 2018
Feel free to try
options = optimoptions('fmincon','GradObj','on','OutputFcn',@outfun);
Or, for people who like to set only one option at a time,
options = optimoptions('fmincon','GradObj','on');
options = optimoptions(options,'OutputFcn',@outfun);
The optimoptions function reference page has all of this information.
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!