2D - Truss Analysis help

8 views (last 30 days)
Ben
Ben on 4 Jul 2014
Answered: marrwa manaa on 22 Oct 2017
Hello all, i've been trying to develop a MATLAB code to analyze a 2-D truss system because I thought it would be a good project to further my understanding (i'm a beginner)
My main function script is here:
function Project
E = 10200000; % Modulus of Elasticity, Aluminum alloy (psi)
A = 200; % Cross-Sectional Area
L = 1; % Length of bar
EA = E*A;
elementNodes = [1 4; 2 4; 3 4; 4 6; 3 6; 3 5; 5 6; 5 7; 6 7];
nodeCoordinates = [0 1 ;0 0 ;1 1 ;1 0 ;2 1 ;2 0 ;3 1 ];
numberElements = size(elementNodes,1);
numberNodes = size(nodeCoordinates,1);
xx = nodeCoordinates(:,1);
yy = nodeCoordinates(:,2);
GDoF = 2 * numberNodes; % degrees of freedom
U = zeros(GDoF,1); % Displacement
force = zeros(GDoF,1);
% gravitational loads
force(4)= -2500;
force(5)= -2500;
force(6)= -2500;
force(7)= -5000;
% system stiffness matrix
[stiffness]=formStiffness2Dtruss(GDoF,numberElements,elementNodes,numberNodes,nodeCoordinates,xx,yy,EA);
% boundary conditions
prescribedDoF = [1 2 10]';
% Solution
displacements = solution(DoF,prescribedDoF,stiffness,force);
us = 1:2:2*numberNodes-1;
vs = 2:2:2*numberNodes;
end
---------------------------- My second script formStiffness2Dtruss (stiffness matrix)- is here :
function formStiffness2Dtruss
elementNodes = [1 4; 2 4; 3 4; 4 6; 3 6; 3 5; 5 6; 5 7; 6 7];
nodeCoordinates = [0 1 ;0 0 ;1 1 ;1 0 ;2 1 ;2 0 ;3 1 ];
numberElements = size(elementNodes,1);
numberNodes = size(nodeCoordinates,1);
stiffness = zeros(numberNodes);
for e=1:numberElements;
% elementDof: element degrees of freedom (Dof)
GDoF=elementNodes(e,:) ;
stiffness(GDoF,GDoF)=stiffness(GDoF,GDoF)+[1 -1;-1 1];
end
end
--------------------------- When I try and run the main function I get the error
Error using formStiffness2Dtruss
Too many input arguments.
Error in Project (line 26)
[stiffness] =
formStiffness2Dtruss(GDoF,numberElements,elementNodes,numberNodes,nodeCoordinates,xx,yy,EA);
--------------------------- I'm not sure what's really going on and how to fix the problem. Any help would be greatly appreciated! Thanks! (To clarify the second script (stiffness matrix) runs fine on it's own)
  1 Comment
Rick Rosson
Rick Rosson on 5 Jul 2014
Functions and scripts are two very different things in MATLAB.

Sign in to comment.

Answers (2)

marrwa manaa
marrwa manaa on 22 Oct 2017
plez if you complete ur program,send to me function script

per isakson
per isakson on 5 Jul 2014
Edited: per isakson on 5 Jul 2014

Community Treasure Hunt

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

Start Hunting!