Global matrix assemblage

My question is really broken into two separate parts.
I have a system of linear bars which are subject to a moment force, each with one degree of freedom per end. I need to find out how much they rotate, this is a pretty simple "stiffness method" matrix problem, I know how to solve it by hand, I just have no idea where to begin in matlab.
We have created the following code to produce a 3 element matrix:
nel= 3; %number of elements
nnodes= 4; %number of nodes
nDOF= 1; % number of degrees of freedom per node
sDOF= nnodes*nDOF; % total number of degrees of freedom in our structure.
G= [80*10^9;40*10^9;20*10^9]; %shear modulus
L= [0.5;08;0.3]; %length of members
d= [0.08; 0.06; 0.04]; %diameters of members as defined in a vector.
F= [3000; 2000; 800]; %force vector collectiong all of the applied moments
K= zeros(sDOF); %preallocation of the global stiffness matrix
for iel= 1:nel
elk= torsion1(G,L,d(iel));
K(iel:iel+1, iel:iel+1)= elk + K(iel:iel+1, iel:iel+1);
end %for
K_ff= K(2:end, 2:end); %apply boundary condistions ( partition )
U_f= K_ff\F;
K_sf= K(1, 2:end);
P_s= K_sf*U_f;
With function:
function [elk]= torsion1(G,L,d) %G = shea modulus in pascals, L = length in meters and d = diameter in meters.
Ip= pi*d^4/32; % polar intertia for shaft
K_T= G*Ip/L; % stiffness
elk= K_T*[1 -1;-1 1]; % nodal stiffness matrix
We now have to modify the code to have nvalue of bars(I.e 1 to infinite), each with its own element stiffness matrix with unique values for the bars properties... I have basically labelled the following :
function [U_f,T_s]= Shaft(N,G,L,d,T)
% N = number of elements
% G = vector for shear modulus of each element
% L = vector for length of each element
% d = vector for diameter of each element
% T = vector for externally applied moments
I just dont know how to create the individual matricies and then assemble them into a global matrix, I need to some how create a different K_T based on the vector values for each bar, the number of K_T's and indeed the number of matricies required will obviously be set by N... am i right ? any help would be greatly appreciated.
P.s i have been using matlab for about 5 days so apologies if this is all really simple stuff to me it makes very little sense currently .. :(
Thanks for any help, kind regards.
Jake.

Answers (2)

ali  badr
ali badr on 21 Mar 2016
I have the same problem Can anyone clarify the whole situation of assembling a global matrix from local matrices? Thanks
Sean de Wolski
Sean de Wolski on 18 Oct 2011

0 votes

Step back and write out how to assemble to element stiffness matrices (transformed if necessary) into a big stiffness matrix. The nodes that are shared are overlapped and summed when the big matrix is formed. It really is just a bunch of book keeping and organization in how you label your nodes/elements.

Asked:

on 18 Oct 2011

Answered:

on 21 Mar 2016

Community Treasure Hunt

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

Start Hunting!