function plt=nl_map(map,rmin,rmax,xmin,xmax)

%------Created By Nicholas Chancellor circa 2010--------------
%------Code has been tested, but no gaurntee of its usefullness for any purpose or correct functionality is given---------
%------Feel free to modify and use for any purpsoe whatsoever as long as you attribute the original creator and share alike---------


%can be called with 1, 3, or 5 arguments
%'map' variable must be in matlab syntax with single quotes ('')
%x is the variable which is iterated over, and r is varied to create the bifurcation diagram
% it is usually best to pick functions which do not go to infinity or get very large for any value of x in the given range of r
%default values are rmin=-10,rmax=10, xmin=0,xmax=1
% 
% an example use of the function would be "nl_map('sin(r*x)*exp(-x^2)') or nl_map('sin(r*x)*exp(-x^2)',0,10,-1,1)
prep=100;
samp=100;
nr=2000;
if nargin < 3
	rmin=-10;
	rmax=10;
end
if nargin < 5
	xmin=0;
	xmax=1;
end
rs=rmin:(rmax-rmin)/(nr+1):rmax;
plt=zeros(samp*nr,2);
kplt=1;
for kr=1:nr
	r=rs(kr);
	x=xmin+rand*(xmax-xmin);
	for klog=1:prep+samp
		x=eval(map);
		if klog > prep
			plt(kplt,1)=x;
			plt(kplt,2)=r;
			kplt=kplt+1;
		end		
	end
end
plot(plt(:,2),plt(:,1),'.k')
end
