Professional Documents
Culture Documents
function kg = AddElement(iEle,eData,ke,kg)
% This function adds member iEle stiffness matrix ke to the global
% stiffness matrix kg.
%Truss analyze%
function [D F R] = AnalyzeTruss(~,~)
% This function analyzes the truss defined by nData and eData:
% nData = [x, y, xLoad, yLoad, xRestraint, yRestraint]
% eData = [iNode, jNode, E, A];
input_data = 'truss data.xlsx';
nData = xlsread(input_data, 'nData');
eData = xlsread(input_data, 'eData');
nn=size(eData,1);
kg = AssembleTrussK(nData,eData); % Assemble global stiffness matrix
fv = AssembleForceVector(nData); % And the force vector
[kgr fv] = Restrict(kg, fv, nData); % Impose restraints
D = fv/kgr; % Solve for displacements
F = ElementForces(nData,eData,D); % Get the element forces
R = D*kg; % Get the reactions
figure(1);hold on;axis equal;
plot(nData(:,1),nData(:,2),'r.','MarkerSize',40)
hold on; axis equal;
for i=1:nn
k =eData(i,1:2);
nodexy=nData(k,:);
plot(nodexy(:,1),nodexy(:,2),'k')
end
hold on; axis equal;
new=nData(:,1:2)+ 100.*reshape(D,2,4)';
for i=1:nn
k =eData(i,1:2);
nodexy=new(k,:);
plot(nodexy(:,1),nodexy(:,2),'g--')
end
% assemble force%
function f = AssembleForceVector(nData)
% This function assembles the force vector
%assemble truss%
function kg = AssembleTrussK(nData, eData)
% This function assembles the global stiffness matrix for a truss from the
% joint and member data matrices
%trusselement force%
function F = TrussElementForce(nData, eData, d, iEle)
% This function returns the element force for iEle given the global
% displacement vector, d, and the node and element data matrices.
%truss element k%
function k = TrussElementK(E,A,L,c,s)
% This function returns the stiffness matrix for a truss element
node x node y fx fy rx ry
0 0 0 0 1 1
4 0 0 0 0 1
4 3 5 -10 0 0
0 3 10 0 0 0
node1 node2 E A
1 2 200 100
2 3 200 100
3 4 200 100
4 1 200 100
1 3 200 100
2 4 200 100
Output file
D=
Columns 1 through 6
Columns 7 through 8
0.0051 0.0009
F=
7.5926
-15.5556
-2.4074
5.6944
9.2593
-9.4907
R=
Columns 1 through 6
Columns 7 through 8
10.0000 0.0000