필터 지우기
필터 지우기

How to use the OutputFcns function in the optimset options?

조회 수: 1 (최근 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 CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by