Permalink
##
Matlab-Programs-for-Nonlinear-Dynamics/

Go to file
Cannot retrieve contributors at this time

# Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

##
Matlab-Programs-for-Nonlinear-Dynamics/**Erdos.m**

Go to file
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

40 lines (26 sloc)
658 Bytes

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters

% function [A,degree,Lap] = Erdos(N,p) | |

% Generates an Erdos-Renyi random graph of N nodes with edge probability p | |

% A is the adjacency matrix | |

% degree is the degree of the node | |

% Lap is the Lapacian matrix | |

function [A,degree,Lap] = Erdos(N,p) | |

e = round(p*N*(N-1)/2); | |

A = zeros(N,N); %Adjacency matrix | |

loop = 0; | |

while loop ~=e | |

% x = round(rand*(N-1))+1; | |

% y = round(rand*(N-1))+1; | |

x = ceil(N*rand); | |

y = ceil(N*rand); | |

flag = A(y,x); | |

if (x~=y)&(flag==0) | |

A(x,y) = 1; | |

A(y,x) = 1; | |

loop = loop +1; | |

end | |

end | |

degree = sum(A); | |

Lap = -A; | |

for loop = 1:N | |

Lap(loop,loop) = degree(loop); | |

end | |