function  [x, Nmx, Nmn] = vargrid(N, alpha, plotflag)
%
%	FUNCTION  [X, Nmax, Nmin] = VARGRID(N, ALPHA, PLOT_FLAG)
%
%	Return vector X of points in the interval [0,1] with
%	point density ranging from Nmax (at 0) to Nmin (at 1).    
%
%	N = Number of points on the basilar membrane
%	ALPHA = spacing increase exponent 
%	X = array of points on the BM with exponentially increasing spacing
%	Nmax, Nnin = maximum and minimum point density on BM 	
%	PLOT_FLAG = plot only if 1

if nargin<3,
	plotflag=0;
end

if nargin<2,
	alpha=1.5;
end

if alpha<0,
	disp('	Second argument must be nonnegative');
	return;
end

xo=(1:N)/N;

dx = exp(alpha*xo);

dx=dx/sum(dx);

x(1)=dx(1);

for i=2:N,
	x(i)=x(i-1)+dx(i);
end

if (x(N) > 1), 
	x(N) = 1; 
end

dens=ones(size(dx))./dx;
Nmx=max(dens);
Nmn=min(dens);

if plotflag==1,
	[xm, im] = min(abs(x-0.5));
	Nmdl=dens(im);

	figure(1);
	clg,
	plot(x,zeros(size(x))+Nmx/2,'.w',x,dens,'-r'), 
	axis([0,1,0,Nmx]);
	text(0.2, 0.95*Nmx, ['Max.density = ', num2str(Nmx)])
	text(0.2, 0.85*Nmx,  ['Mid.density = ', num2str(Nmdl)])
	text(0.2, 0.75*Nmx, ['Min.density = ', num2str(Nmn)])
	title('Red curve represents point density'), pause
	axis;
	fl=input('Enter 1 if the set of points is accepted  ->  ');
	disp(' ');
	if fl ~= 1,
		disp('	Set of points refused. Tray again.');
		return
	end
end