function [L,C]=SmallWorldsEx(n,K,P,N);
%SmallWorldsEx.m---repeats Watts & Strogatz (1998) small-world experiments
%
%[L,C]=SmallWorldsEx(n,k,P,N);
%
%Repeats the experiment in Watts & Strogatz (1998)"Collective 
%dynamics of 'small-world' networks", Nature, 393:440:442.  The
%experiment creates random lattices with n vertices and k connections.
%The degree of randomness of the lattices is controlled by the
%vector P of probabilities.  The experiment creates N lattices
%for each entry in P.  The outputs L and C are the mean path-length
% and cluster coeffients for each probability, normalized by the
%values for a graph with p=0 (a regular lattice).
%
%Related functions:
%
%		G=createlattice(n,k,P(j))--creates a lattice
%		[l,c]=latticestats(G)    --statistics for a lattice
%      
%      you can visualize a lattice with plotlattice.m
%

m=length(P);
L=zeros(m,N);%initialize storage for L and C
C=L;		    %  L(j,:)=[L(G1),..., L(GN)] where the G's are graphs p=P(j)
for j=1:m
	p=P(j);
	for k=1:N
   	G=createlattice(n,K,p);% Create a new graph
      disp([j,k])
      [L(j,k),C(j,k)]=latticestats(G); %Save stats in L and C
   end
end
G=createlattice(n,K,0);
[l0,c0]=latticestats(G); %Gets stats for an ordered graph
L=mean(L')'/l0;	%Compute means for each P, scale
C=mean(C')'/c0;
