# Adjacency matrix with periodic boundaries

12 Ansichten (letzte 30 Tage)
L am 5 Okt. 2023
Verschoben: Dyuman Joshi am 18 Nov. 2023
I have a 2-dimensional square lattice of nodes .
I need to find the distance between the nodes (adjacency matrix), but I should account for periodic boundary conditions. This means that the 2d sheet of nodes must first be wrapped into a torus, and then I should assess the distances between the nodes. I can find the adjacency matrix for a few number of nodes. But I wonder if there is a more general method that I could use to code a function that given the number of nodes in the 2D lattice would return the adjacency matrix.
I read that the adjacency matrix could be computed by using a sum of kronecker products. But I did not understand it.
Any help?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Ayush Anand am 19 Okt. 2023
Hi,
I understand you are trying to compute the adjacency matrix for a 2D lattice with periodic boundary conditions. You can use the concept of a Kronecker product for the same. The Kronecker product allows you to construct a larger matrix by taking all possible combinations of elements from two smaller matrices.
You can follow the steps below to construct the adjacency matrix for a 2D lattice with periodic boundary conditions:
1. Define the adjacency matrix for a single row or column of nodes: You can start by creating a matrix that represents the adjacency relationships between neighboring nodes in a single row or column.
2. Compute the adjacency matrix for a 2D lattice: To obtain the adjacency matrix for the entire 2D lattice, you can use the Kronecker product to combine the adjacency matrices for the rows and columns.
3. Apply periodic boundary conditions: To account for periodic boundary conditions, you need to consider the wrap-around connections between the first and last rows/columns of the lattice. This can be achieved by taking the Kronecker product of the adjacency matrix with a circulant matrix that represents the wrap-around connections.
You can use the "kron" function in MATLAB to compute the Kronecker product and the "circulant" function to generate the circulant matrix. A sample code for the above steps could be as follows:
% Define the dimensions of the lattice
m = 3; % number of rows
n = 4; % number of columns
% Adjacency matrix for a single row
row_adjacency = eye(n) + circshift(eye(n), [0, 1]) + circshift(eye(n), [0, -1]);
% Adjacency matrix for a single column
column_adjacency = eye(m) + circshift(eye(m), [1, 0]) + circshift(eye(m), [-1, 0]);
% Compute adjacency matrix for the 2D lattice
% Apply periodic boundary conditions
wrap_around_adjacency = kron(circulant(ones(m, 1)), eye(m*n)) + kron(eye(m*n), circulant(ones(n, 1)));
You can refer to the following page for more details on the "kron" function and the "circulant" function:
I hope this helps!
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
JOHN NIKI am 18 Nov. 2023
Verschoben: Dyuman Joshi am 18 Nov. 2023
wrap_around_adjacency = kron(circulant(ones(m, 1)), eye(m*n)) + kron(eye(m*n), circulant(ones(n, 1)));
Arrays have incompatible sizes for this operation.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by