%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  function [ f ] = func( x, t, y )
%
%  Purpose
%
%       Calculates the value of the objective function of 
%       Example 2.1 in J. Nocedal and S. J. Wright, "Numerical 
%       Optimization", Springer-Verlag, 1999
%
%  Parameters
%
%  On entry:
%
%     x        nx1 vector with approximated parameters.
%
%     t        mx1 vector with times of the observations.
%
%     y        mx1 vector with measured observations. 
%
%  On return:
%
%     f        value of the objective function.
%
%
%  Written by L. N. Vicente.
%  February 21, 2000.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
  function [ f ] = func( x, t, y )
%
% Calculate the residual vector at current x.   
  r = y - x(1) - x(2)*exp(-(x(3)-t).^2/x(4)) - x(5)*cos(x(6).*t);
%
% Calculate the objective function.
  f = sum( 0.5 * r.^2 );
%
% End of function func.
