Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Writing matrix for 2D plane of atoms

Asked by SAZZAD HOSSAIN

SAZZAD HOSSAIN (view profile)

on 22 Jun 2013

Hello all

I have a row of 100 atoms and i am considering nearest neighbour interaction. What that means is that each atom has an interaction with itself (self interaction) of magnitude 2; and each atom interacts with its two nearest neighbour atoms from each side of magnitude 1. This 1D problem is represented in matrix as

 2  1  0 0 0 0 ...
-1  2  1 0 0 0 ...
 0 -1  2 1 0 0 ...
 0  0 -1 2 1 0 ...
 .............
 .............

Now, my problem is that i dont know how to write this matrix when instead of a 1D problem, i have a 2D plane of atoms with the same nearest neighbour interaction condition. Can someone please help me ???

Thanks in advance.

Sazzad

0 Comments

SAZZAD HOSSAIN

SAZZAD HOSSAIN (view profile)

Tags

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov

Andrei Bobrov (view profile)

on 22 Jun 2013
Accepted answer
a = [-1 2 1];
n = 100;
m = numel(a)-1;
out = full(spdiags(ones(n,1)*[-1 2 1],-m:m,n,n));

0 Comments

Andrei Bobrov

Andrei Bobrov (view profile)

Contact us