How to use the OutputFcns function in the optimset options?

2 ビュー (過去 30 日間)
Sheng Liu
Sheng Liu 2012 年 3 月 5 日
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 Center および File ExchangeOptimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by