Effacer les filtres
Effacer les filtres

A small question about the OutputFcn function in the optimization tool~~Thank you!

1 vue (au cours des 30 derniers jours)
Sheng Liu
Sheng Liu le 6 Mar 2012
in this page there is a example to answer my former question I posted yestoday. you can see it in the Example of a Nested Output Function headline~~
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
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!!!!

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by