Filter löschen
Filter löschen

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

6 Ansichten (letzte 30 Tage)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 30 Jan. 2016
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)

Weitere Antworten (1)

Guillaume
Guillaume am 27 Jan. 2016
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 Kommentare
amar
amar am 27 Jan. 2016
I want to assemble this matrix for any number of nodes 'n'
Walter Roberson
Walter Roberson am 27 Jan. 2016
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)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by