function fcontour(fname,x_int,y_int,num_con)
% This function is designed to produce a contour plot of either
% a function of two variables defined via an M-file or an expression
% in x and y that is entered as a string. Here are three examples:
% 
% EXAMPLE 1.
%
%       fcontour('sin(x.*y)',[-1,1],[0,3], 40)
%
% Here, 40 contours of the surface f(x,y)=sin(x y) are plotted on the 
% rectangle with x between -1 and 1 and y between 0 and 3.
% 
% 
% EXAMPLE 2.
%
%       fcontour('sin(x.*y)',[-1,1],[-1,1])
%
% This is the same plot as before, except the number of contours
% is 20, the default value.
%
% EXAMPLE 3.
%       
%       fcontour('my_function',[5,17],[-pi,pi])
%    
% The contours of a  function called my_function, which is defined in 
% terms of an M-file, is plotted. The independent variable is between 
% 5 and 17, and the dependent variable is between -pi and pi. The 
% default value (20) is used for the number of contours.
% 
% This M-file is based on MATLAB's fplot function, and was written by
% Professor F. J. Narcowich, Sept. 9, 1996.
 
a=x_int(1,1);
b=x_int(1,2);
c=y_int(1,1);
d=y_int(1,2);
[X,Y]=meshgrid(linspace(a,b,20),linspace(c,d,20));
x=X; 
y=Y;
if nargin<4,
   nc=20;
else,
   nc=num_con;
end

if ~any(fname < 48) & ~strcmp(fname,'x') & ~any(fname == 94) 
  fcall = [fname,'(x,y)'];
  Independent_Variable='Independent Variable';
  Dependent_Variable='Dependent Variable';
else
  fcall = fname;
  Independent_Variable='x';
  Dependent_Variable='y';
end
Z=eval(fcall);
sc=contour(X,Y,Z,nc);
title(['Contour plot of ',fname])
xlabel(Independent_Variable)
ylabel(Dependent_Variable)
%clabel(sc)
