Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Matrix creation with specific logic

1 回表示 (過去 30 日間)
Zeaid
Zeaid 2013 年 10 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.

回答 (1 件)

Jie
Jie 2013 年 10 月 8 日
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'

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by