Assembling Global Stiffness Matrix
159 views (last 30 days)
Show older comments
I am trying to make a global stiffness matrix using a for loop from several smaller (4X4) matrices. I was able to get a loop to run for 2X2 matrices, but when I increase the number of rows and colums in my smaller matrices it no longer works. I want the loop to run when the kn matrices is rand(4). This is what I have currently:
k1=rand(2);
k2=rand(2);
k3=rand(2);
C = {k1,k2,k3};
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
disp(M)
0 Comments
Answers (2)
Torsten
on 12 Dec 2022
This is analogous to your 2x2 code.
I don't know if it's the right way to code M.
k1=rand(4);
k2=rand(4);
k3=rand(4);
C = {k1,k2,k3};
N = numel(C);
M = zeros(3+N,3+N);
for k = 1:N
M(k:k+3,k:k+3) = M(k:k+3,k:k+3)+C{k};
end
disp(M)
2 Comments
Arif Hoq
on 13 Dec 2022
% creating stiff matrix
for i=1:20
stiff{i}=randi(100,4,4);
end
k1=stiff(1);
k2=stiff(2);
k3=stiff(3);
k4=stiff(4);
k5=stiff(5);
k6=stiff(6);
k7=stiff(7);
k8=stiff(8);
k9=stiff(9);
k10=stiff(10);
k11=stiff(11);
k12=stiff(12);
k13=stiff(13);
k14=stiff(14);
k15=stiff(15);
k16=stiff(16);
k17=stiff(17);
k18=stiff(18);
k19=stiff(19);
k20=stiff(20);
C = [k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,k17,k18,k19,k20];
N=numel(C);
M = zeros(N,N);
for k = 1:N-3
M(k:k+3,k:k+3) = M(k:k+3,k:k+3)+C{k};
end
disp(M)
0 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!