필터 지우기
필터 지우기

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