function mse = cost(x,a)
% COST2 is the MatLab function that evaluates the Mean Square Error between 
% the Gaussian function with parameters x = [mean, variance] and the data 
% points a = [abscissa points; ordinate points].
%
%  Written by: M.A. van Wyk (c)
%        Date: 3 July 2006

% Retrieve measurements
xp = a(1,:);   % Abscissa of the measurements
fxp = a(2,:);  % Ordinate of the measurements

% Retrieve Gaussian parameters
m = x(1);      % Mean
v = x(2);      % Variance

% Calculate the MSE of the fit
fx = 1/sqrt(v*2*pi)*exp(-(xp-m).^2/2/v);
e = fx - fxp;
mse = sum(e.^2);

%fx = abs(a*x);