Info

此问题已关闭。 请重新打开它进行编辑或回答。

Matrix creation with specific logic

2 次查看(过去 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