Finite Elements Method creating global stiffness matrix

22 views (last 30 days)
Hi everyone, I am really stuck in creating a code that creates global stiffness matrix that changing local stiffness matrixes value in every cycle.
For example it has to be
k1 -k1 0 0
-k1 k1+k2 - k2 0
0 - k2 k2+k3 -k3
0 0 -k3 k3
but my code doesn't change k1 to k2 for next step ... it only calculates for k1.
k1 -k1 0 0
-k1 k1+k1 - k1 0
0 - k1 k1+k1 -k1
0 0 -k1 k1
Please help me to solve this problem. Thanks.
clear
tp=[1 2]
for i=2:4
tp(i,:)=tp(i-1,:)+1
end
tpmax=max(max(tp));
KG=zeros(tpmax,tpmax);
for i=1:4
d(i)=32+(28/1200)*(2*i-1)*50
G(i)=(77000*pi*d(i).^4)/3200
k=[G(i) -G(i);-G(i) G(i)]
end
for n=1:4
i=n+[0 1]
j=i
KG(i,j)=KG(i,j)+k
end
  2 Comments
Mehmet Ali kurt
Mehmet Ali kurt on 27 Apr 2020
Hi Omer ; If you have solition of 'Derived stiffness matrix for 1D 3-Nodes elements' can you send me please ?

Sign in to comment.

Accepted Answer

Stephan
Stephan on 15 Mar 2019
Edited: Stephan on 15 Mar 2019
Hi,
you overwrite k every time. Im sure it could be done much easier - but here s a quick solution without any code optimization (Matlab users usually try to avoid for loops...):
clear
tp=[1 2];
for i=2:4
tp(i,:)=tp(i-1,:)+1;
end
tpmax=max(max(tp));
KG=zeros(tpmax,tpmax);
for i=1:4
d(i)=32+(28/1200)*(2*i-1)*50;
G(i)=(77000*pi*d(i).^4)/3200;
k(:,:,i)=[G(i) -G(i);-G(i) G(i)];
end
for n=1:4
i=n+[0 1];
j=i;
KG(i,j)=KG(i,j)+k(:,:,n);
end
Result is:
KG =
1.0e+08 *
0.9147 -0.9147 0 0 0
-0.9147 2.1154 -1.2006 0 0
0 -1.2006 2.7494 -1.5488 0
0 0 -1.5488 3.5165 -1.9677
0 0 0 -1.9677 1.9677
I think this is what you expected.
Best regards
Stephan

More Answers (0)

Categories

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

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!