필터 지우기
필터 지우기

Matrix form for a square lattice arrangement.

조회 수: 7 (최근 30일)
Vira Roy
Vira Roy 2021년 10월 6일
댓글: Vira Roy 2021년 10월 7일
Question: I want to have a matrix form for hopping between nearest points on a square lattice.
My Attempt: To start and explain the idea I do that on a 1D lattice like shown in the figure
The matrixForm for this case comes from this.
I create a 1D chain using the following code (I use a fucntion SquareGrid defined below)
N = 3; % Number of points
pts = squareGrid([0 0 (N-1) 0], [1 1]);
scatter(pts(:,1),pts(:,2),50,'o', 'filled')
Now I want a matrixform such that I can see hopping between the sites which are neigbors. First and last sites are linked. For this i do the following.
N =5; % Number of sites
t = 1; % value for hopping
t_vec = repmat(t, [1,N-1]); % making a vector of size N-1 with t
H_tb = diag(t_vec, 1) + diag(t_vec, -1);
H_tb(1,5) = t; H_tb(5,1) = t; % linking first and last points
H_tb
H_tb = 5×5
0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 1 0 0 1 0
Now I have the matricform as shown above which does what I wanted for a 1D chain. Now i want to do the same for 2D, square lattice. This is where I am stuck. How do make a matrixform such as above which takes into account all the hoppings between nearest sites? Any help would be appreciated. Thank You.
pts = squareGrid([0 0 1 1], [1 1]);
scatter(pts(:,1),pts(:,2),50,'o', 'filled')
For this I use a function SquareGrid as below.
function varargout = squareGrid(bounds, dim)
%bounds(xmin,ymin,xmax,ymax)
% dim(xsep, ysep) eg. dim(4,2) makes separation b/w points xpoints as 4 and
% ypoints as 2
x1 = bounds(1);
x2 = bounds(3);
lx = (x1: dim(1):x2)';
y1 = bounds(2);
y2 = bounds(4);
ly = (y1: dim(2):y2)';
%number of points in each coordinate
nx = length(lx);
ny = length(ly);
np = nx * ny;
%Creating Points
pts = zeros(np,2);
for i = 1:ny
pts((1:nx)' + (i-1) * nx, 1) =lx;
pts( (1:nx)'+(i-1)*nx, 2) = ly(i);
end
if nargout > 0 % if number of function arguments is > zero
varargout{1} = pts;
end
end
  댓글 수: 2
Matt J
Matt J 2021년 10월 6일
How large can N be?
Vira Roy
Vira Roy 2021년 10월 6일
Thanks for your reply Matt. I do want to genralise it for arbitrary n but for this sake I am looking at a 2 *2 grid of square lattice. In the end i would like to do higher n like 3 or 4. I merely want to undersatnd the technique to do that.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2021년 10월 6일
For an arbitray lattice, you can always just use pdist2,
D=pdist2(pts,pts,'cityblock');
H_tp=(D==1);
This is without your circulant end conditions. The circulancy doesn't generalize in any obvious way to hexagonal or other arbitrary lattices, so I don't know in general what you would want to do. For a rectangular lattice, you would do,
e11=pts(:,1)==1; e1N=pts(:,1).'==N;
e21=pts(:,2)==1; e2N=pts(:,2).'==N;
E1=(e11&e1N); E1=E1|E1.';
E2=(e21&e2N); E2=E2|E2.';
H_tp=(D==1) | E1 | E2;
  댓글 수: 1
Vira Roy
Vira Roy 2021년 10월 7일
Matt, thank you for the solution. It has helped me and so I am accepting the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2021년 10월 6일
편집: Matt J 2021년 10월 6일
If N^2 isn't too large,
N=4;
h_tb=sparse( toeplitz([0,1,zeros(1,N-3),1]) ); %1D
A=kron(ones(N),h_tb);
B=kron(h_tb,ones(N));
H_tb=xor(A,B); %2D
H_tb = 16×16 sparse logical array
(2,1) 1 (4,1) 1 (5,1) 1 (7,1) 1 (10,1) 1 (12,1) 1 (13,1) 1 (15,1) 1 (1,2) 1 (3,2) 1 (6,2) 1 (8,2) 1 (9,2) 1 (11,2) 1 (14,2) 1 (16,2) 1 (2,3) 1 (4,3) 1 (5,3) 1 (7,3) 1 (10,3) 1 (12,3) 1 (13,3) 1 (15,3) 1 (1,4) 1 (3,4) 1 (6,4) 1 (8,4) 1 (9,4) 1 (11,4) 1 (14,4) 1 (16,4) 1 (1,5) 1 (3,5) 1 (6,5) 1 (8,5) 1 (9,5) 1 (11,5) 1 (14,5) 1 (16,5) 1 (2,6) 1 (4,6) 1 (5,6) 1 (7,6) 1 (10,6) 1 (12,6) 1 (13,6) 1 (15,6) 1 (1,7) 1 (3,7) 1 (6,7) 1 (8,7) 1 (9,7) 1 (11,7) 1 (14,7) 1 (16,7) 1 (2,8) 1 (4,8) 1 (5,8) 1 (7,8) 1 (10,8) 1 (12,8) 1 (13,8) 1 (15,8) 1 (2,9) 1 (4,9) 1 (5,9) 1 (7,9) 1 (10,9) 1 (12,9) 1 (13,9) 1 (15,9) 1 (1,10) 1 (3,10) 1 (6,10) 1 (8,10) 1 (9,10) 1 (11,10) 1 (14,10) 1 (16,10) 1 (2,11) 1 (4,11) 1 (5,11) 1 (7,11) 1 (10,11) 1 (12,11) 1 (13,11) 1 (15,11) 1 (1,12) 1 (3,12) 1 (6,12) 1 (8,12) 1 (9,12) 1 (11,12) 1 (14,12) 1 (16,12) 1 (1,13) 1 (3,13) 1 (6,13) 1 (8,13) 1 (9,13) 1 (11,13) 1 (14,13) 1 (16,13) 1 (2,14) 1 (4,14) 1 (5,14) 1 (7,14) 1 (10,14) 1 (12,14) 1 (13,14) 1 (15,14) 1 (1,15) 1 (3,15) 1 (6,15) 1 (8,15) 1 (9,15) 1 (11,15) 1 (14,15) 1 (16,15) 1 (2,16) 1 (4,16) 1 (5,16) 1 (7,16) 1 (10,16) 1 (12,16) 1 (13,16) 1 (15,16) 1
  댓글 수: 1
Vira Roy
Vira Roy 2021년 10월 6일
This seems to work Matt and I am thankful for your solution as well but unfortunately this is not what i was hoping for. I wanted to use the function SquareGrid to make the points and then loop around them to find the matrix elements of the matrix. The reason being that I wanted to learn the technqiue of doing that so later i can try the idea for different grid system like say hexagonal lattice for which I have function as well similar to SquareGrid.
Thanks for the help though and if you have some idea of how should i approach like i mentioned it would be helpful.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by