フィルターのクリア

Adjacency matrix with periodic boundaries

12 ビュー (過去 30 日間)
L
L 2023 年 10 月 5 日
移動済み: Dyuman Joshi 2023 年 11 月 18 日
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?

回答 (1 件)

Ayush Anand
Ayush Anand 2023 年 10 月 19 日
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
adjacency = kron(row_adjacency, eye(m)) + kron(eye(n), column_adjacency);
% Apply periodic boundary conditions
wrap_around_adjacency = kron(circulant(ones(m, 1)), eye(m*n)) + kron(eye(m*n), circulant(ones(n, 1)));
adjacency = adjacency + wrap_around_adjacency;
You can refer to the following page for more details on the "kron" function and the "circulant" function:
I hope this helps!
  1 件のコメント
JOHN NIKI
JOHN NIKI 2023 年 11 月 18 日
移動済み: Dyuman Joshi 2023 年 11 月 18 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by