%**********************************************************
%  MATLAB mfile that plots a 2D Gaussian function and 
%  computes equiprobable contours 
%  AUTHOR: Balu Santhanam
%  DATE  : 09/01/2000
%**********************************************************
% Set up grids for the X and Y coordinates
x = [3:0.15:7]; y = [3:0.15:7];
% Compute Grid Matrices
[xgrid,ygrid]= meshgrid(x,y);
%  Mean Vector
mu = [5;5]; 
%  Covariance Matrix
sigma = [5.5,2;2,6]; 
%  Correlation Coefficient
rho = sigma(1,2)/sqrt((sigma(1,1)*sigma(2,2)));
s1 = sigma(1,1);
s2 = sigma(2,2);
%  Contour values
v = (1/(2*pi))*exp(-2.^-[0:1:8]);
z = (1/(2*pi))*(1/(abs(det(sigma)))*exp(-1/(0.5*sqrt(1-rho^2))*...
((xgrid-mu(1)).^2/s1-rho/sqrt(s1*s2)*(xgrid-mu(1)).*(ygrid-mu(2))+((ygrid-mu(2)).^2/s2))));
mesh(xgrid,ygrid,z)
hold on
contour(xgrid,ygrid,z)
set(gca,'FontName','Helvetica','FontSize',15)
xlabel('x variable')
ylabel('y variable')
zlabel('z variable')
title('2D Gaussian and Equiprobable contours')
axis square
orient tall 
hold off
print -deps gaus.eps



