how would I add several matrices into one? (assembling global stiffness matrix for FEA)
44 ビュー (過去 30 日間)
古いコメントを表示
I want to add several 4X4 matrices into one large one (see attached image for my general goal). This is to assemble a global stiffness matrix of several bar elements. I will have 205 matrices to add into 1 large one, but I figure it would be easiest to get an understanding by attempting to assemble the matrices in the image I atttached.
here is how I presume you'd start:
A = [1 1; 1 1];
B = [1 1; 1 1];
K = zeros(3,3); %empty matrix to add A & B to
How would I continue?
0 件のコメント
採用された回答
Stephen23
2020 年 3 月 26 日
編集済み: Stephen23
2020 年 3 月 26 日
This is easy when you store all of the matrices in one cell array, then you just need a simple for loop:
>> 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
A more illustrative example:
>> C = {[1,1;1,1],[1,1;1,1],[2,3;4,5],[6,7;8,9]};
>> 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 0 0
1 2 1 0 0
0 1 3 3 0
0 0 4 11 7
0 0 0 8 9
Here are some other answers on this topic:
0 件のコメント
その他の回答 (1 件)
Peng Li
2020 年 3 月 26 日
To achieve your example, it's easy. You just need to think a bit about matrix multiplication. see below
>> A = [1 1; 1 1];
>> B = [1 1; 1 1];
>>
>> helperA = [1 0; 0 1; 0 0];
>> helperB = [0 0; 1 0; 0 1];
>> helperA*A*helperA' + helperB*B*helperB'
ans =
1 1 0
1 2 1
0 1 1
Not quite sure about your actual case. It might be easy to generalize this math to fit your goal. Hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!