MATLAB When having a two-dimensional lattice, in lexocographic order I need to be able to move around from the original site and to the four nearest neighbors. I created the code for the site to the right side and the site above, but I cannot make the ones for the site below and to the left side to work. Furthermore, we have some border conditions, meaning that when considering a site on the border the code should return the site from the beginning or end of the lattice. (Periodic boundary condition). In other words, this means that if the run iup(1,7) it returns 8, iup(2,7) = 11, idn(1,7)=6, idn(2,7)=3 and for the borders iup(1,8)=5 and idn(2,1)=13. The ones that won't work and I need help with are the two idn. K = 16; h = sqrt(K); for a = 1:h for b = 1:h lex(a,b)=a+(b-1)*h; x(lex(a,b))=a; y(lex(a,b))=b; end end for a = 1:K iup(1,a) = lex(mod(x(a),h)+1,y(a)); iup(2,a) = lex(x(a),mod(y(a),h)+1); idn(1,a) = lex(mod(x(a),h)-1,y(a)); idn(2,a) = lex(x(a),mod(y(a),h)-1); end
MATLAB
When having a two-dimensional lattice, in lexocographic order I need to be able to move around from the original site and to the four nearest neighbors. I created the code for the site to the right side and the site above, but I cannot make the ones for the site below and to the left side to work. Furthermore, we have some border conditions, meaning that when considering a site on the border the code should return the site from the beginning or end of the lattice. (Periodic boundary condition). In other words, this means that if the run iup(1,7) it returns 8, iup(2,7) = 11, idn(1,7)=6, idn(2,7)=3 and for the borders iup(1,8)=5 and idn(2,1)=13. The ones that won't work and I need help with are the two idn.
K = 16;
h = sqrt(K);
for a = 1:h
for b = 1:h
lex(a,b)=a+(b-1)*h;
x(lex(a,b))=a;
y(lex(a,b))=b;
end
end
for a = 1:K
iup(1,a) = lex(mod(x(a),h)+1,y(a));
iup(2,a) = lex(x(a),mod(y(a),h)+1);
idn(1,a) = lex(mod(x(a),h)-1,y(a));
idn(2,a) = lex(x(a),mod(y(a),h)-1);
end
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)