Borrar filtros
Borrar filtros

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

6 visualizaciones (últimos 30 días)

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de En. de 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)

Más respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by