How to use the OutputFcns function in the optimset options?

2 次查看(过去 30 天)
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!

回答(1 个)

Seth DeLand
Seth DeLand 2012-3-5
  1 个评论
Sheng Liu
Sheng Liu 2012-3-6
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by