Info

This question is closed. Reopen it to edit or answer.

Matrix creation with specific logic

2 views (last 30 days)
Zeaid
Zeaid on 7 Oct 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi all, I have a question, I'm trying to create the following matrix with the given logic. Can someone help figuring this out? Thanks
let B be an n^2 * n^2 matrix such that B is symmetric
let the function: index(L,m) = L + (m - 1)n defined for 1<= L <= n & 1<= m <= n
so that
B(index(L,m),index(L,m)) = 4
and when it makes sense
B(index(L,m),index(L+1,m)) = -1
B(index(L,m),index(L-1,m)) = -1
B(index(L,m),index(L,m+1)) = -1
B(index(L,m),index(L,m-1)) = -1
where n = 4.

Answers (1)

Jie
Jie on 8 Oct 2013
If i did not take the def wrong, I'm afraid ur definition just gives (at most) the value of 90 different position in a matrix(for n=4),notice u have 4^2*4^2=256 position in a matrix. What about other un-defined positions? Anyway, the following is provided for ur reference:
n=4;l=n^2;
a=2*diag(ones(1,l));
for i=1:15
a(i+1,i)=-1;
if i+4<16
a(i+4,i)=-1;
end
end
A=a+a'

Tags

Community Treasure Hunt

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

Start Hunting!