MATLAB Answers

0

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?

Asked by Devanjith Fonseka on 21 Mar 2018
Latest activity Commented on by Devanjith Fonseka on 21 Mar 2018
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)

  0 Comments

Sign in to comment.

1 Answer

Answer by Alan Weiss
on 21 Mar 2018
 Accepted Answer

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

  1 Comment

Thanks a ton! The first method worked for me. You are truly a Matlab god!

Sign in to comment.