フィルターのクリア

How to add values for a variable in a loop?

1 回表示 (過去 30 日間)
Adi
Adi 2017 年 12 月 20 日
コメント済み: Adi 2017 年 12 月 20 日
clc
clear all
disp('Finding Stiffness, Displacement & Reactions of a 2nd Order Bar Element ')
disp('....INPUTS....')
L=60;
E=1000;
Area=10;
Ne=1;%#OF ELEMENTS
o=[];%o=end condition when free & 1=when fixed
%Ne=input('Number of elements=')
%Le=input('Total Length of bar=')
%E=input('Elastic Modulus=')
%Area=input('Area=')
disp('APPLYING EXTERNAL Boundry Conditions')
n1=1
nn=o
%n1=input('1st Node=')
%nn=input('end Node=')
%BCs=[N1,Nn]%end conditions,1ST AND LAST NODES ARE FIXED
% generation equal spaced coordinates
C=E*Area;
%Shape Functions
co=linspace(0,L,Ne+2)%Dividing Element into Equal SEGMENTS
% n: number of nodes
n=size(co,2)
%Excitation vector
KG=zeros(n,n);%global stiffness matrix(rows,columns)
FG=zeros(n,1);%Global Forces(rows,columns)
disp('.......ASSEMBLYING GLOBAL STIFFNESS MATRIX........')
%ii=1:Ne+1
%en2(:,1)=ii
%en2(:,2)=ii+1
%en2(:,3)=ii+2
en2=[1 2 3;3 4 5;5 6 7;7 8 9;9 10 11]
for e=1:Ne+1
% eDof: element degrees of freedom (Dof)
eDof=en2(e,:)%when e=1 it will display 1st row of eDof
%Le=Length/Ne; %LENGTH OF EACH ELEMENT
Le=co(eDof(2))-co(eDof(1))
syms x
N1=((co(eDof(2)) -(x))*(co(eDof(3)) -(x)))/((co(eDof(2))-co(eDof(1)))*(co(eDof(3))-co(eDof(1))))
N2=((co(eDof(1)) -(x))*(co(eDof(3)) -(x)))/((co(eDof(1))-co(eDof(2)))*(co(eDof(3))-co(eDof(2))))
N3=((co(eDof(1)) -(x))*(co(eDof(2)) -(x)))/((co(eDof(1))-co(eDof(3)))*(co(eDof(2))-co(eDof(3))))
shape(:,1)=N1
shape(:,2)=N2
shape(:,3)=N3
B=diff(shape)
BT=B.'
b=BT*B
x=0.5774 % kindly Help me to put value of x in b
b=BT*B
Ke=b*C*Le
KG(eDof,eDof)=KG(eDof,eDof)+ Ke
Fe=ff*Le/2*[1;1]
FG(eDof)=FG(eDof)+Fe
end
%Ke=C*[1,-1;-1,1]
disp('APPLYING EXTERNAL FORCE')
%fn=input('External Force at node=')
fn=n
%f=input('External Force value=')
f=10
FG(fn)=FG(fn)+f %Force at a perticular node
disp('Global Stiffness Matrix')
KG
disp('Load Matrix')
FG
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Boundry Conditions
if n1==1 & isempty(nn);%1=fixed & 0=free
c=2
d=n
BCs=[1]
disp('Loop 1')
elseif isempty(n1) & nn==1;
c=1
d=n-1
BCs=[n]
disp('Loop 2')
else n1==1 & nn==1;
c=2
d=n-1
BCs=[1,n]
disp('Loop 3')
end
MatA=KG(BCs,c:d)%auxaliry equation for initial and final conditions selecting 1st row 2nd & 3rd col.
MatB=FG(BCs)%Aux. Right Hand side i-e force vector
%disp('Matrix witout BC rows')
KG(BCs,:)=[]; %Matrix witout BC rows
%disp('Matrix witout BC columns')
KG(:,BCs)=[];%Matrix witout BC columns
%disp('Matrix without BC rows from force matrix')
FG(BCs)=[]; %Matrix without BC rows from force matrix
disp(' Stiffness & Force Matrix for displacement cal. ')
KG
FG
disp('Displacements')
Displacements=inv(KG)*FG
disp('Reactions')
Reactions=MatA*Displacements-MatB
  4 件のコメント
Adi
Adi 2017 年 12 月 20 日
sorry about line 57! its the line where i have given x=0.5774
Adi
Adi 2017 年 12 月 20 日
Alternatively I can use Integration to solve for element Stiffness Matrix "ke" but again I dont know how to Integrate Matrix.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by