How to use the OutputFcns function in the optimset options?

2 views (last 30 days)
Hi everybody!Now I'm using the fminsearch function in the optimization tool.For at here we
cannot upload a picture I have to describe it fully by characters. if you type 'doc optimset',you will see the help manual about the question I mentioned. you see the bold letters'option'?and the line 5,the OutputFcn?
OutputFcn
function | {[]}
User-defined function that an optimization function calls at each iteration.
fminbnd, fminsearch,fzero
as it was described,we can use a user-defined function to put out some other function called at
each iteration.
But ,it didn't give an example in detail,so how to use it ?could you please give an detailed
introduction of it?thank you so much!

Answers (1)

Seth DeLand
Seth DeLand on 5 Mar 2012
  1 Comment
Sheng Liu
Sheng Liu on 6 Mar 2012
OK!thank you so much!I've happened to find the same page that you pointed out,haha~~
And still a little question:
with this example changed something,just like this(for I don't need the history variable):
function [x fval] = myproblem1(x0) options = optimset('OutputFcn', @myoutput,'Display','iter');
[x fval] = fminsearch(@objfun, x0,options);
function stop = myoutput(x,~,state)
stop = false;
if state == 'iter'
disp([' x = ',num2str(x)]);
end
%disp(sprintf('\n\n'))
end
function z = objfun(x)
z = exp(x(1))*(4*x(1)^2+2*x(2)^2+x(1)*x(2)+2*x(2));
end
end
and then I input the commmand:
[x fval] = myproblem1([-1 1])
it did give a right result.
but if you input:
objfun(x)
it comes out like this:
> objfun(x)
ans =
0.3344
I don't understand,doesn't the return value of the fminsearch function equal to the minimum value of objfun(x)?So,why doesn't the ans above equal to -0.5689,as written in the help page you mentioned?
Thank you!!!!
my question is,i

Sign in to comment.

Categories

Find more on Optimization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!