% EVALUATE THE FUNCTION
%
% This matlab file will calculate the result f(x,y)
% of a certain function f, evaluated in the point (x,y).
% 
% This matlab file will calculate the result gradient of
% of a certain function f, evaluated in the point (x,y).
% Also the gradient of this function will be calculated.
%
% The file can also calculate the values of Z, for plotting
% the figure.
%
% Software written by Raf Vandebril
% Raf.Vandebril-at-cs.kuleuven.be
% Revision Date: 10/05/2010


function [fxy,grad,Z]=xyfunc(xinput,X,Y)
  
  
  %----------------------------------------------
  
  if (nargin==1)
    % Pay attention: xinput is generically a vector
    x=xinput(1);
    y=xinput(2);
    
    % CHANGE if you change the function
    % In order to calculate this we define here the function,
    fxy=x^4+(4*y+1)^2+1;
    
    % CHANGE if you change the function
    % The gradient is a column vector with the first component:
    % df/dx, and the second component df/dy evaluated in x,y
    grad(1,1)= 4*x^3;
    grad(2,1)= 2*4*(4*y+1);
    
    % REMARK, if there is an error here in the evaluation of the gradient,
    % probably there will occur an error in the steepest descent method.
  end
  
  %----------------------------------------------------------
  
  % CHANGE if you change the function
  % This last function is necessary for plotting the figures:
  % REMARK, put a dot before the ^, i.e. use .^ instead of ^
  % also use .* instead of *
  if (nargin==3) % nargin equals the number of input elements
    fxy=0;grad=0;
    Z=X.^4+(4*Y+1).^2+1;
  end
  
