A small question about the OutputFcn function in the optimization tool~~Thank you!
2 次查看(过去 30 天)
显示 更早的评论
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!!!!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Programming and Mixed-Integer Linear Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!