Assemble Global Stiffness Matrix
7 views (last 30 days)
Show older comments
%% INPUTs:
A = 2300; % Cross-Sectional Area of member (in mm^2)
E = 2*10^5; % Elastic Modulus (in N/mm/mm)
L(:,1) = 4000; % Length of Member-1 (in mm)
L(:,2) = 6000; % Length of Member-2 (in mm)
t(:,1) = 0; % Theta-1
t(:,2) = 90; % Theta-2
t(:,3) = rad2deg(atan(L(:,2)/L(:,1))); % Theta-3
N = numel(t)
%% OUTPUTs:
L(:,3) = sqrt(L(:,1)^2 + L(:,2)^2); %Length of Member-3 (in mm)
for i = 1:N
k{i} = [A*E/L(:,i) 0 -A*E/L(:,i) 0;0 0 0 0;-A*E/L(:,i) 0 A*E/L(:,i) 0;0 0 0 0];
C{1,i} = [cosd(t(:,i)) -sind(t(:,i)) 0 0;sind(t(:,i)) cosd(t(:,i)) 0 0;0 0 cosd(t(:,i)) -sind(t(:,i));0 0 sind(t(:,i)) cosd(t(:,i))];
D{1,i} = transpose(C{1,i});
K{1,i} = C{1,i}*k{1,i}*D{1,i};
end
From this code, I'm able to get (4*4) size [K] matrices such that K{1,1} = K1; K{1,2} = K2 & K{1,3} = K3. Now, I want them to assemble in such a way that it ends up into a global matrices of K (6*6) matrix.
K{1,1} - U1 V1 U2 V2
K{1,2} - U2 V2 U3 V3
K{1,3} - U1 V1 U3 V3
Need global assembly matrix such that: [K] based on U1 V1 U2 V2 U3 V3. For more clarification, I'm attaching image.
0 Comments
Accepted Answer
Voss
on 1 Mar 2024
%% INPUTs:
A = 2300; % Cross-Sectional Area of member (in mm^2)
E = 2*10^5; % Elastic Modulus (in N/mm/mm)
L(:,1) = 4000; % Length of Member-1 (in mm)
L(:,2) = 6000; % Length of Member-2 (in mm)
t(:,1) = 0; % Theta-1
t(:,2) = 90; % Theta-2
t(:,3) = rad2deg(atan(L(:,2)/L(:,1))); % Theta-3
N = numel(t)
%% OUTPUTs:
L(:,3) = sqrt(L(:,1)^2 + L(:,2)^2); %Length of Member-3 (in mm)
for i = 1:N
k{i} = [A*E/L(:,i) 0 -A*E/L(:,i) 0;0 0 0 0;-A*E/L(:,i) 0 A*E/L(:,i) 0;0 0 0 0];
C{1,i} = [cosd(t(:,i)) -sind(t(:,i)) 0 0;sind(t(:,i)) cosd(t(:,i)) 0 0;0 0 cosd(t(:,i)) -sind(t(:,i));0 0 sind(t(:,i)) cosd(t(:,i))];
D{1,i} = transpose(C{1,i});
K{1,i} = C{1,i}*k{1,i}*D{1,i};
end
%% assemble global K:
idx = {1:4, 3:6, [1 2 5 6]};
K_global = zeros(6);
for ii = 1:numel(idx)
K_global(idx{ii},idx{ii}) = K_global(idx{ii},idx{ii})+K{ii};
end
%% display global K:
format short g
disp(K_global)
More Answers (1)
Aquatris
on 1 Mar 2024
I think this is what you are looking for. You can extend the logic in a better way if you have more than 3 nodes.
% create random 4x4 matrices with different magnitude to see the results
% clearly
K1 = rand(4);
K2 = rand(4)+10;
K3 = rand(4)+100;
K = zeros(6); % initialize global K
idx_1 = [1 2]; % column and row number corresponding to U1 V1
idx_2 = [3 4]; % column and row number corresponding to U2 V2
idx_3 = [5 6]; % column and row number corresponding to U3 V3
% Assemble the K matrix
K([idx_1 idx_2],[idx_1 idx_2]) = K([idx_1 idx_2],[idx_1 idx_2]) + K1; % U1 V1 U2 V2 part
K([idx_2 idx_3],[idx_2 idx_3]) = K([idx_2 idx_3],[idx_2 idx_3]) + K2; % U2 V2 U3 V3 part
K([idx_1 idx_3],[idx_1 idx_3]) = K([idx_1 idx_3],[idx_1 idx_3]) + K3; % U1 V1 U3 V3 part
disp(K)
See Also
Categories
Find more on Robotics 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!