function globalplot(a, b, c)

% Plots a parametric version of the "peaks" function 
% for use in the global optimization exercise. 

[x,y] = meshgrid(-3:0.1:3);

z =  a*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
   - b*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
   - c*exp(-(x+1).^2 - y.^2);

surf(x,y,z)
shading interp
axis([-3 3 -3 3 min(min(z)) max(max(z))])
xlabel('x'), ylabel('y')

% Create title:

if a == 0 
   str1 = [];
elseif a == 1 
   str1 = '(1-x)^2e^{[-x^2-(y+1)^2]}'; 
else
   str1 = [num2str(a), '(1-x)^2e^{[-x^2-(y+1)^2]}'];
end

if b == 0 
   str2 = [];
elseif b == 1 
         str2 = ' -(x/5-x^3-y^5)e^{[-x^2-y^2]}'; 
else
   if b > 0
      str2 = [' -', num2str(b), '(x/5-x^3-y^5)e^{[-x^2-y^2]}'];
   else
      if a ~= 0
      str2 = [' +', num2str(-b), '(x/5-x^3-y^5)e^{[-x^2-y^2]}'];
      else
      str2 = [num2str(-b), '(x/5-x^3-y^5)e^{[-x^2-y^2]}'];
      end
   end
end

if c == 0 
   str3 = [];
elseif c == 1 
         str3 = ' -e^{[-(x+1)^2-y^2]}'; 
else
   if c > 0
      str3 = [' -', num2str(c), 'e^{[-(x+1)^2-y^2]}'];
   else
      if a ~= 0 | b ~= 0 
      str3 = [' +', num2str(-c), 'e^{[-(x+1)^2-y^2]}'];
      else
      str3 = [num2str(-c), 'e^{[-(x+1)^2-y^2]}'];
      end
   end
end

title([str1, str2, str3])