function analysis = fixed_points( perm_size, run_time, last_fix_pt )
%fixed_points counts the number of fixed points in run_time permutations of
%size perm_size.

%details: The program runs an experiment run_time times which counts the
%number of fixed points in a random permutation of size perm_size. 
%The variable analysis stores the results. In general analysis(i) returns 
%the number of permutations with i-1 fixed points. 
%The program looks for permutations with up to last_fix_pt fixed points. 
%It's unlikely there are very many fixed points, so a good number value for
%last_fix_pt is 20. 

%NB to calculate the percentage of permutatiobs with i fixed points, one
%must divide analysis(i+1) by run_time.

%%% Created by Greg Petrics, Dartmouth College. This program can be modified in
%%% any way the user deems fit. It comes with absosolutely no warranty.

order=1:perm_size;
dater=zeros(1,run_time);

for i=1:run_time
temp=randperm(perm_size);
compare=temp-order;
samespots=find(compare==0);
n=length(samespots);
dater(i)=n;
clear temp compare samespots n
end
analysis=zeros(1,last_fix_pt);
for j=1:last_fix_pt
temp=find(dater==(j-1));
num=length(temp);
analysis(j)=num;
end

end

