Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Matrix creation with specific logic

2 vues (au cours des 30 derniers jours)
Zeaid
Zeaid le 7 Oct 2013
Clôturé : MATLAB Answer Bot le 20 Août 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.

Réponses (1)

Jie
Jie le 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!

Translated by