Is it possible to create periodic boundary conditions for a matrix with linear indexing?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tom Edwards
le 2 Déc 2019
Modifié(e) : David Goodmanson
le 2 Déc 2019
Is it possible to create periodic boundary conditions for a matrix with linear indexing?
I created a matrix say LxL, it is populated with 1's or 0's to represent the presence of a particle or empty space. I'll calculate the total energy of the matrix by calculating the sum of the energy of the nearerst neighbours, i.e. the North, South, East and West compartments of an occupied cell will contribute some energy if also occupied. If I select a cell at the edge or corner of the matrix I need to specify that the end position of row 1 should neighbour to the first position in row 1, and the same system for all other boundary positions. Is there a way of doing this with linear indexing? Or maybe I should say, is there a way of doing this without ind2sub for a general LxL matrix?
Thanks
0 commentaires
Réponse acceptée
David Goodmanson
le 2 Déc 2019
Modifié(e) : David Goodmanson
le 2 Déc 2019
Hi Tom,
mod(k,N)+1 for the raised index, k+1
mod(k-2,N)+1 for the lowered index, k-1
and these do give the correct vector of indices for k = 1:N
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!