%%%This Shows The Precolation vs ocupency for all square matrix upto n
%%it will go through all permibility values from 0 to 1 and plot
%%percoaltion vs ocuupency vs n
%only edit n
n=5;
%%
k=0;
p=0:0.01:1;
cycle=20;
temp =size(p);
iter=temp(2);
storageall10p=zeros(iter,n);
storageall10o=zeros(iter,n);
sto_n=zeros(iter,n);
for n=1:n
sto_n(:,n)=n;
for iter=1:iter
percolated=0;
occu_avg=0;
for cyc= 1:cycle
A=randsrc(n,n,[0 1;(1-p(iter)) p(iter)]);
B=zeros(n,n);
% figure;
% cmap = [1,1,0;0,1,1];
% colormap(cmap);
% set(gcf,'Position', [0 0 n*100 n*100])
% imagesc(A);
% colorbar;
p_count = 0;
for j=1:n
if A(1,j)==1
p_count= count(A,1,j,n,n,0,B);
if p_count==1
break
end
end
end
if p_count>0
percolated=percolated+1;
end
occu_avg=sum(A(:))/(n*n)+occu_avg;
% caption = sprintf('Percolation paths = %d %%, Occupancy = %d %% ', p_count,occu_per);
% title(caption);
% pause(1)
end
storageall10p(iter,n)=percolated*100/cycle;
storageall10o(iter,n)=occu_avg*100/cycle;
end
end
polyfitallmat(storageall10o, sto_n, storageall10p)
function [fitresult, gof] = polyfitallmat(storageall10o, sto_n, storageall10p)
%CREATEFIT(STORAGEALL10O,STO_N,STORAGEALL10P)
% Create a fit.
%
% Data for 'polyfitallmat' fit:
% X Input : storageall10o
% Y Input : sto_n
% Z Output: storageall10p
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 05-Nov-2019 19:03:37
%% Fit: 'polyfitallmat'.
[xData, yData, zData] = prepareSurfaceData( storageall10o, sto_n, storageall10p );
% Set up fittype and options.
ft = fittype( 'poly33' );
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft );
% Plot fit with data.
figure( 'Name', 'polyfitallmat' );
plot( fitresult, [xData, xData], zData );
%legend( h, 'polyfitallmat', 'storageall10p vs. storageall10o, sto_n', 'Location', 'NorthEast' );
% Label axes
xlabel Occupency
ylabel n
zlabel Percolation
grid on
view( 5.3, 23.6 );
end
function [pc] = count(A,i,j,n,m,pc,B)
if i==n||pc==1
%B=test_matrix;
% figure;
% cmap = [1,1,0;0,1,1;0,0,1];
% set(gcf,'Position', [0 0 n*100 m*100])
% imagesc(B);
% colorbar;
% title("B ");
% colormap(cmap);
% colorbar;
% pause(0.05);
pc=1;
return ;
end
if pc==0
test_matrix=A;
test_matrix(i,j)=2;
if i~=n
if(test_matrix(i+1,j)==1)
[pc]=count(test_matrix,i+1,j,n,m,pc,B);
end
end
if j~=1&&i~=1
if (test_matrix(i,j-1)==1)
[pc]=count(test_matrix,i,j-1,n,m,pc,B);
end
end
if j~=m&&i~=1
if(test_matrix(i,j+1)==1)
[pc]=count(test_matrix,i,j+1,n,m,pc,B);
end
end
if i~=1
if(test_matrix(i-1,j)==1)
[pc]=count(test_matrix,i-1,j,n,m,pc,B);
end
end
end
end