gistlib
# Create a community matrix community_matrix <- matrix(c(1,1,0,0, 1,1,0,0, 0,0,1,1, 0,0,1,1), nrow=4, byrow=TRUE) # Find the Laplacian matrix laplacian_matrix <- diag(rowSums(community_matrix)) - community_matrix # Normalize the Laplacian matrix D_half <- diag(sqrt(1/rowSums(community_matrix))) normalized_laplacian <- D_half %*% laplacian_matrix %*% D_half # Print the matrices print("Community Matrix:") print(community_matrix) print("Laplacian Matrix:") print(laplacian_matrix) print("Normalized Laplacian Matrix:") print(normalized_laplacian) 638 chars21 lines
# Create a community matrix community_matrix <- matrix(c(1,1,0,0, 1,1,0,0, 0,0,1,1, 0,0,1,1), nrow=4, byrow=TRUE) # Find the Laplacian matrix laplacian_matrix <- diag(rowSums(community_matrix)) - community_matrix # Normalize the Laplacian matrix D_half <- diag(sqrt(1/rowSums(community_matrix))) normalized_laplacian <- D_half %*% laplacian_matrix %*% D_half # Print the matrices print("Community Matrix:") print(community_matrix) print("Laplacian Matrix:") print(laplacian_matrix) print("Normalized Laplacian Matrix:") print(normalized_laplacian)
gistlibby LogSnag