n number of 2x2 matricies to diagonal matrix

6 visualizaciones (últimos 30 días)
k
k el 29 de Mzo. de 2020
Comentada: k el 29 de Mzo. de 2020
I have a 2x2 matrix that I need put into the diagonal of a matrix n times. In other words, on each diagonal, a new 2x2 matrix prints. For cells with two k values, they should be added together.
For example:
n = 3:
k -k 0 0
-k k+k -k 0
0 -k k+k -k
0 0 -k k
What I have:
n = input('Input the number of elements:');
k = ((E * avg_area)/L)*[+1 -1; -1 +1];
for n;
k_global = diag(k);
end

Respuesta aceptada

David Hill
David Hill el 29 de Mzo. de 2020
n = input('Input the number of elements:');
k = ((E * avg_area)/L);
k_global=diag([k,repmat(k+k,1,n-1),k])+diag(repmat(-k,1,n),-1)+diag(repmat(-k,1,n),1);

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by