function plotcont (obj, x0, xg, yg)
%   Plot function for ACM 113, Problem 3.5

if nargin < 3,
    xg = -4:0.1:4;
    yg = xg;
end

[x1, x2] = meshgrid(xg, yg);
z = zeros(size(x1));
for i = 1 : length(xg),
    for j = 1 : length(yg),
        eval(['z(j, i) = ' obj '([xg(i); yg(j)]);']);
    end
end

[xm, fm, xlist] = trust_region('obj3_5', x0);

yl = zeros(1, length(xlist));
for i = 1:length(xlist),
    eval(['yl(i) = ' obj '([xlist(1,i); xlist(2,i)]);']);
end

figure; hold on;
contour(x1, x2, z, [-100:10:0]);

plot(xlist(1, :), xlist(2,:), 'o--');
for i = 1 : length(xlist)
    text(xlist(1,i)+0.08,  xlist(2, i) + 0.1, int2str(i-1));
end

axis([-3.8,3.9,-3.3,3.1]);
title(['Find f_{min} = ' num2str(fm) ' within ' int2str(length(xlist)-1) ' iterations']);
xlabel('x_1');
ylabel('x_2');
