Filter löschen
Filter löschen

n number of 2x2 matricies to diagonal matrix

4 Ansichten (letzte 30 Tage)
k
k am 29 Mär. 2020
Kommentiert: k am 29 Mär. 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

Akzeptierte Antwort

David Hill
David Hill am 29 Mär. 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);

Weitere Antworten (0)

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by