在MATLAB中绘制优化解决方案

时间:2016-12-25 02:41:10

标签: matlab optimization

我正在使用以下功能和fminunc来绘制情节

function stop = bananaout(x, optimValues, state)
    stop = false;
    hold on;
    plot(x(1),x(2),'.');
    drawnow
end

我的情节如下所示,

enter image description here

如何让它看起来如下?

我是否需要修改我的bananaout或驱动程序?

enter image description here

源代码

    function [x, fval, eflag, iter, fcount] = Optimization_With_Steepest_Descent(start_point)
    fun = @(x)(100*(x(2) - x(1)^2)^2 + (1 - x(1))^2);
    x0 = start_point;

    % optimoptions setup
    options = optimoptions('fminunc','Display','off', 'OutputFcn',@bananaout,'Algorithm','quasi-newton');
    options = optimoptions(options,'HessUpdate','steepdesc', 'MaxFunEvals',600);

    % call fminunc
    [x,fval,eflag,output] = fminunc(fun,x0,options);


    title 'Rosenbrock solution via steepest descent'

    iter = output.iterations;
    fcount = output.funcCount;

    disp('Press any key to continue...');
end

0 个答案:

没有答案