Waste less time on Facebook — follow Brilliant.
×

Adjacency matrix for a square lattice

I am trying to create an adjacency matrix for \(n\times n\) square lattice. If \((i,j)\) denotes a vertex in the lattice then I first index all the nodes in the lattice using a single index \(k\) such that \(k=(i-1)*n+j\). After that I want to write \(n^2\times n^2\) adjacency matrix. But I am not able to do it properly. Please help me. Thank you

Note by Snehal Shekatkar
3 years, 12 months ago

No vote yet
1 vote

Comments

Sort by:

Top Newest

You move between adjacent vertices in the same row by adding or subtracting \(1\), and you move between adjacent vertices in the same column by adding or subtracting \(n\). Thus vertex \(k\) is adjacent to:

  1. Vertex \(k+1\), unless \(n\) divides \(k\),

  2. Vertex \(k-1\), unless \(n\) divides \(k-1\),

  3. Vertex \(k+n\), unless \(k+n > n^2\),

  4. Vertex \(k-n\), unless \(k-n\le 0\).

Adjacency matrices for \(2\times2\) and \(3\times3\) grids are \[ \left(\begin{array}{cccc}0&1&1&0\\1&0&0&1\\1&0&0&1\\0&1&1&0\end{array}\right) \qquad \qquad \left(\begin{array}{ccccccccc}0&1&0&1&0&0&0&0&0\\1&0&1&0&1&0&0&0&0\\0&1&0&0&0&1&0&0&0\\ 1&0&0&0&1&0&1&0&0\\0&1&0&1&0&1&0&1&0\\0&0&1&0&1&0&0&0&1\\ 0&0&0&1&0&0&0&1&0\\0&0&0&0&1&0&1&0&1\\0&0&0&0&0&1&0&1&0 \end{array}\right) \] Mark Hennings · 3 years, 12 months ago

Log in to reply

@Mark Hennings Yess.. I modified my code and it works perfectly now!! Thank you very much sir! Snehal Shekatkar · 3 years, 12 months ago

Log in to reply

@Mark Hennings Thank you. This really looks cool.. I will modify my code now. I was mainly having problem at edges but now I got your idea of checking whether \(n\) divides those indices or not. I will get back to you soon. Snehal Shekatkar · 3 years, 12 months ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...