n number of 2x2 matricies to diagonal matrix

4 次查看(过去 30 天)
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

采纳的回答

David Hill
David Hill 2020-3-29
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);

更多回答(0 个)

类别

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