Adding matrices (to assemble global stiffness matrix)

23 Ansichten (letzte 30 Tage)
Ryan Yeo
Ryan Yeo am 22 Nov. 2021
Kommentiert: Ryan Yeo am 23 Nov. 2021
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 Kommentar
David Hill
David Hill am 22 Nov. 2021
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 22 Nov. 2021
Bearbeitet: David Goodmanson am 23 Nov. 2021
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 Kommentare
David Goodmanson
David Goodmanson am 23 Nov. 2021
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 am 23 Nov. 2021
Hi David,
Thank you for spotting the mistake! And thanks for clearing the confusion up, I've managed to obtain my global stiffness matrix!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays 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