function ginger(a,b,numiterations)
% ginger Is a function for plot gingerBread map [1] [2] [3].
%
% The gingerbreadman map is given by the trnasformation:
% (1)
% x(i) = 1 - a*y(i-1) + b*abs(x(i-1));
% y(i) = x(i-1);
%
% In original form a=1 and b=1. here we can change these parameters
% to explore diferent atractors.
%
% INPUTS:
% a = This is the a parameter on ecuation (1)
% b = This is the b parameter on ecuation (1)
% numiterations = This set the number of iterations of ecuation (1)
%
%
% Example (1):
%
% ginger(1.40,1,10000)
%
%
% Example (2):
%
% We can take frames and create a movie showing the evolution
%
% for i=1:1500
% ginger(2*(i-1)/1500,1,2000)
% axis([-20,20,-20,20])
% M(i)=getframe(gcf)
% end
%
% movie(M)
%
% I uploaded that movie to youtube:
% http://www.youtube.com/watch?v=5k18BuEES34
%
%
% References:
% [1] Loren on the Art of MATLAB, "Pretty 2-Dimensional Chaotic Maps",
% http://blogs.mathworks.com/loren/2011/12/07/pretty-2-dimensional-cha
% otic-maps/
%
% [2] Wikipedia, "Gingerbread Map",
% http://en.wikipedia.org/wiki/Gingerbreadman_map
%
%
% [3] Adam Wachsman "Gingerbreadman chaotic 2D map",
% http://www.mathworks.com/matlabcentral/fileexchange/34116
%
%This function was written by :
% Hctor Corte
% B.Sc. in physics 2010
% Battery Research Laboratory
% University of Oviedo
% Department of Electrical, Computer, and Systems Engineering
% Campus de Viesques, Edificio Departamental 3 - Office 3.2.05
% PC: 33204, Gijn (Spain)
% Phone: (+34) 985 182 559
% Fax: (+34) 985 182 138
% Email: cortehector@uniovi.es
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This is just for security, you can change it to get better images, but
%carefully.
maxnumofiterations=10000;
if numiterations>maxnumofiterations
numiterations=maxnumofiterations;
display('Number of iterations exceed max number of iterations')
end
%We are going to calculate simultaneusly the path of 100 randon points
x=20*(rand(100,numiterations)-0.5);
y=20*(rand(100,numiterations)-0.5);
%This is the main loop, where iterations takes place
for i=1:numiterations
y(:,i+1)=x(:,i);
x(:,i+1)=1-b*y(:,i)+a*abs(x(:,i));
end
%Once we got all the points we have to plot them all.
for kj=1:100
plot(x(kj,:),y(kj,:),'.k','markersize',0.5)
hold on
end
title(['a=',num2str(a),'; b=',num2str(b)],'FontSize', 20);
hold off