%%%%%%% ESTIMATING LAMBDA %%%%%%% doc errorbar % this function is really helpful, so it's worth reading the documentation % on how it works! % use 'doc XYZ' to open the documentation file for any function XYZ X = [1/1024,1/512,1/256,1/128]; % our vector for 1/L Y = [1.65,1.65,1.66,1.67]; % our vector of measured values of \lambda_c E = [0.01,0.01,0.01,0.01]; % our errors (here assumed to be symmetric) errorbar(X,Y,E) % plot the results!! % From here, we can fit a linear (or polynomial...) function from % the plot window by clicking 'tools > basic fitting' % Alternatively, we can click the tab labelled 'APPS' at the top of the MATLAB window % and open up cftool, the curve fitting tool. From here, we specify the X % data, the Y data and the type of function we want to fit, choose the % parameters of that function and the cftool should perform the fitting % automatically. % From there, we click the fitted model in the 'Table of fits' (at the bottom % of the cftool window, and right click to bring up the option for 'save % untitled fit to workspace'. This will create a few variables in the % workspace with silly names. % To plot the fitted model, you type 'plot(fittedmodel)' and there you have % it! The fit is stored in a special kind of data structure that will % automatically plot in a red line if used as an argument in the 'plot' % function. % N.B. make sure to type 'hold on' if you would like to plot this fit on % top of an existing plot containing data. %%%%%%% WIGNER SEMICIRCLE LAW %%%%%%% % Firstly, let's generate an Erdos-Renyi random graph matrix: % Let's have N=1000 and z=1.5, therefore p = z/N = 1.5/1000 adj = random_graph(1000,0.015); % Now we want the eigenvectors and eigenvalues of this matrix [V,E] = eig(adj); % N.B. E is a diagonal vector with the eigenvalues along the diagonal, so % if we ask for 'sum(E)' we will get a 1D array of the row-sums, which will % thus just be a 1D array of the eigenvalues % So now, let's plot the graph spectrum using ksdensity, firstly it might % be nice to remind ourselves what ksdensity can and will do: doc ksdensity % So, it will fit a gaussian around each point, and even around points % where we have no samples, so in the second argument it ksdensity, we need % to tell it only to generate the density plot at the points where we have % actually collected data i.e. at the actual eigenvalues themselves! So: [f,x] = ksdensity(sum(E),sum(E),'bandwidth',0.1); % We've asked for a gaussian of bandwidth 0.1 fitted around the points % sum(E) and only sampled at points sum(E), f and x now contain the desnity % function and sample points respectively, let's plot them in some subtle % blue circles plot(x,f,'bo') % Now, to compare this to the Wigner SemiCircle Law % The spectrum should be approximately semicircular, with radius \Sigma s = 0.015*(1-0.015); % variance of bernoulli rv X = [-2*(sqrt(1000*s)):0.01:2*(sqrt(1000*s))]; % points to plot the semicircle at (from -radius to radius) Y = (1/(2*pi*1000*s))*sqrt(4*1000*s-X.*X); % semicircle function hold on % hold our previous plot!! plot(X,Y,'r-') % plot the semicircle! % Now we just do the same thing for a few other values of z and see how the % spectrum compares to the semicircle in each case % N.B. it is totally expected that the actual graph spectrum will look a % bit 'wobbly' for certain parameters values (even the spectrum can end up % looking quite rude...) and you may want to comment on why this is % Afterwards, we can use the preferential attachment code to generate the % adjacency matrix for a preferential attachment graph and see how the % spectrum compares