How to generate an nxn matrix using n number of 2x2 matrices?

8 views (last 30 days)
Hi,
I am having trouble generating a code in the exisiting loop to create a global stiffness matrix from each element stiffness matrix. I am trying to program matlab to do something similar to this.
I have written the code and loop to generate the connectivity matrix and each element stiffness matrix. I am hoping to use the same loop to generate the global stiffness matrix.
e = %connectivity table
1 1 2
2 2 3
3 3 4
4 4 5
5 5 6
6 6 7
%element stiffness matricies
ke(:,:,1) =
1.5708 -1.5708
-1.5708 1.5708
ke(:,:,2) =
0.8836 -0.8836
-0.8836 0.8836
ke(:,:,3) =
0.6981 -0.6981
-0.6981 0.6981
ke(:,:,4) =
0.6136 -0.6136
-0.6136 0.6136
ke(:,:,5) =
0.5655 -0.5655
-0.5655 0.5655
ke(:,:,6) =
0.5345 -0.5345
-0.5345 0.5345
>>
Can anyone help me?
Thank you!
%Element connectivity Table
n=6; %creates 6 elements
e=[]; %creates empty connectivity matrix
k=[1 -1;-1 1]; %standard format of K
ke=[]; %creates empty element stiffness matrix
Ae=[]; %creates empty element area amatrix
ks=zeros(n,n);
E=1;
L=2;
R1=1;
R2=0.5;
i=1;
for m=1:n; %goes through each element
i=i;
j=i+1;
x=L/m;%thickness of each slice of the beam
A1=pi()/L^2*(R2*L+(R1-R2)*x)^2;%area of each slice of the beam
Ae(:,m)=[A1];%stores each area in a matrix
e(m,:)= [m i j];%stores results in matrix
ke(:,:,m)=E*Ae(:,m)/L*k; %stores each element stiffness matrix
end
  4 Comments
Guillaume
Guillaume on 23 Jan 2019
I'm also not sure what the question is. Furthermore, as far as I can tell you explain how to form a matrix for two springs in series but not when they're in parallel. I don't know anything about stiffness matrices, but I would assume the result is not the same for parallel springs.
I can see several possible question with what you have described. Given a connectivity table, the first task would probably be to find which springs are in parallel and which are in series. Once that is done you would then have to assemble the matrices according to the relevant formula. It's not clear which part of this you need help with.
Monique Embury
Monique Embury on 23 Jan 2019
In my problem, the springs are in series.
The image posted is an example of what I am trying to do. In the example, 2 2x2 matrices are combined to make a 3x3 matrix.
I am trying to combine 6 2x2 matrices to create a 6x6 matrix in a similar fashion. I am not sure how to program this. That is what I am seeking help on.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 24 Jan 2019
"I am trying to combine 6 2x2 matrices to create a 6x6 matrix in a similar fashion"
According to your algorithm the stiffness matrix will be 7x7 not 6x6. It is trivial to achieve
% inputs:
% ke: a 2x2xN matrix
stiffness_matrix = zeros(size(ke, 3) + 1); %create a (N+1)x(N+1) matrix of 0s
for idx = 1:size(ke, 3)
stiffness_matrix(idx:idx+1, idx:idx+1) = stiffness_matrix(idx:idx+1, idx:idx+1) + ke(:, :, idx);
end
  10 Comments
Guillaume
Guillaume on 29 Jan 2019
The construction of the stiffness matrix can only happen after KE has been fully constructed, not during the construction, so move that code after the c loop.

Sign in to comment.

More Answers (1)

jahanzaib ahmad
jahanzaib ahmad on 22 Jan 2019
Edited: Guillaume on 23 Jan 2019
u just want to add stiffness matrix of each element to get n x n stiffness matrix

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!