# Define the 3x3 adjacency matrix
W <- matrix(c(0, 1, 0,
1, 0, 1,
0, 1, 0), ncol=3)
# Non-sparse cases
laplacian_mat(W, "unnormalized")
laplacian_mat(W, "normalized")
laplacian_mat(W, "randomwalk")
# Convert W to a sparse matrix
W_sparse <- as(W, "sparseMatrix")
# Sparse cases
laplacian_mat(W_sparse, "unnormalized")
laplacian_mat(W_sparse, "normalized")
laplacian_mat(W_sparse, "randomwalk")
Run the code above in your browser using DataLab