필터 지우기
필터 지우기

How to Assemble the matrix shown in the image on Matlab for any number of nodes?

조회 수: 6 (최근 30일)

채택된 답변

Walter Roberson
Walter Roberson 2016년 1월 30일
n = 4; %for example
main_diagonal = [ [-4, repmat(-3,1,n-2), -4], repmat([-5, repmat(-4,1,n-2), -5], 1, 2), [-6, repmat(-5,1,n-2), -6] ];
N = length(main_diagonal);
m = diag(ones(1, N-4), -4) +
diag(ones(1, N-1), -1) +
diag(main_diagonal) +
diag(ones(1, N-1), 1) +
diag(ones(1, N-4), -4)

추가 답변 (1개)

Guillaume
Guillaume 2016년 1월 27일
There is not enough information to know how to construct the main diagonal, but you can just sum a bunch of diag:
m = diag(ones(1, 12), -4) + ...
diag(ones(1, 15), -1) + ...
diag([-4 -3 -3 -4 -5 -4 -4 -5 -5 -4 -4 -5 -6 -5 -5 -6], 0) + ... %no idea what the pattern is
diag(ones(1, 15), 1) + ...
diag(ones(1, 12), 4)
  댓글 수: 2
amar
amar 2016년 1월 27일
I want to assemble this matrix for any number of nodes 'n'
Walter Roberson
Walter Roberson 2016년 1월 27일
main_diagonal = [-4 -3 -3 -4 -5 -4 -4 -5 -5 -4 -4 -5 -6 -5 -5 -6]; %we do not know the rule for this
n = length(main_diagonal);
m = diag(ones(1, n-4), -4) +
diag(ones(1, n-1), -1) +
diag(main_diagonal) +
diag(ones(1, n-1), 1) +
diag(ones(1, n-4), -4)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by