Adding matrices (to assemble global stiffness matrix)

22 次查看(过去 30 天)
I want to add several 4X4 matrices into one large one, see code below on method. This is to assemble a global stiffness matrix of several bar elements. I will have 3 matrices to add into 1 large one, but I am stuck in modifying the code to add 3 4x4 matrices into one 6x6.
A simple example:
C = {[1,1;1,1],[1,1;1,1]}; % <- all matrices
N = numel(C);
M = zeros(1+N,1+N);
for k = 1:N, M(k:k+1,k:k+1) = M(k:k+1,k:k+1)+C{k}; end
M
M =
1 1 0
1 2 1
0 1 1
  1 个评论
David Hill
David Hill 2021-11-22
You will have to explain more fully what you want to do. Adding 3 4x4 matrices (total elements=48) into 6x6 matrix (total elements= 36), how are you suppose to do that? Where is the overlap between matrices?

请先登录,再进行评论。

采纳的回答

David Goodmanson
David Goodmanson 2021-11-22
编辑:David Goodmanson 2021-11-23
Hi Ryan,
here is an example. In the code below, a and b are the indices of the 4x4 submatrix of K that each stiffness submatrix is going to be dropped into. Here it's assumed that the upper left of each 4x4 submatrix is going to be put on the the diagonal of K, i.e. (1,1), (2,2) and (3,3) for K1,K2,K3 respectively, but even that does not have to be true. Not likely in this case, but you could have for example a1 = [1:4]; b1 = [2 :5]; which puts the upper left corner of K1 onto K(1,2).
a2 and b2 show that K2 can be spread out through K if that's what it takes.
K1 = randi(10,4,4);
K1 = K1 + K1'
K2 = randi(10,4,4);
K2 = K2 + K2'
K3 = randi(10,4,4);
K3 = K3 + K3'
K = zeros(6,6);
a1 = [1:4];
b1 = [1:4];
a2 = [2 3 5 6];
b2 = [2 3 5 6];
a3 = [3:6];
b3 = [3:6];
K(a1,b1) = K(a1,b1) + K1;
K(a2,b2) = K(a2,b2) + K2;
K(a3,b3) = K(a3,b3) + K3;
K
  3 个评论
David Goodmanson
David Goodmanson 2021-11-23
Hi Ryan,
Two of the stiffeness matrices are not symmetric, is that correct?
To avoid confusion between K and the index k, I modified the answer so that the indices are a and b.
For the stiffness matrix, you effectively have six objects connected with springs, but I can't comment without knowing something about the geometry. So, for example if a certain entry in K2 represents object 2 connected to object 6, then both a2 and b2 will contain 2 and 6 as indices. That will put an entry into K(2,6) and K(6,2). And so forth. This is under the assumption that K is symmetric in which case K1 is symmetric and a1 and b1 are identical, same for 2 and 3.
Ryan Yeo
Ryan Yeo 2021-11-23
Hi David,
Thank you for spotting the mistake! And thanks for clearing the confusion up, I've managed to obtain my global stiffness matrix!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by