# How to make these truss analysis direct stiffness method files connect inputs and outputs?

10 visualizaciones (últimos 30 días)
Quincey Jones el 28 de Mzo. de 2020
Editada: Anurag Agrawal el 31 de Mzo. de 2020
Frank McHugh (2020). Truss Analysis (https://www.mathworks.com/matlabcentral/fileexchange/38044-truss-analysis), MATLAB Central File Exchange. Retrieved March 28, 2020.
function D=Data
% Definition of Data
% Nodal Coordinates
Coord=[-37.5 0 200;37.5 0 200;-37.5 37.5 100;37.5 37.5 100;37.5 -37.5 100;-37.5 -37.5 100;-100 100 0;100 100 0;100 -100 0;-100 -100 0];
% Connectivity
Con=[1 2;1 4;2 3;1 5;2 6;2 4;2 5;1 3;1 6;3 6;4 5;3 4;5 6;3 10;6 7;4 9;5 8;4 7;3 8;5 10;6 9;6 10;3 7;4 8;5 9];
% Definition of Degree of freedom (free=0 & fixed=1); for 2-D trusses the last column is equal to 1
Re=zeros(size(Coord));Re(7:10,:)=[1 1 1;1 1 1;1 1 1;1 1 1];
% or: Re=[0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;1 1 1;1 1 1;1 1 1;1 1 1];
% or: Load=1e3*[1 -10 -10;0 -10 -10;0.5 0 0;0 0 0;0 0 0;0.6 0 0;0 0 0;0 0 0;0 0 0;0 0 0];
% Definition of Modulus of Elasticity
E=ones(1,size(Con,1))*1e7;
% or: E=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]*1e7;
% Definition of Area
A=[.4 .1 .1 .1 .1 3.4 3.4 3.4 3.4 .4 .4 1.3 1.3 .9 .9 .9 .9 1 1 1 1 3.4 3.4 3.4 3.4];
% Convert to structure array
File 2:
%function [F,U,R]=ST(D)
% Analyize a Truss using the direct stiffness method
%
% Input D defines the Truss structure as follows
% D.Coord -- N x 3 array of node coordinates
% D.Con -- N x 2 array of connector or member mapping
% D.Re -- N x 3 array of node freedom 1 = fixed 0 = free
% D.A -- M x 1 array of member cross section areas
% D.E -- M x 1 array of member Elasticity ( Youngs Modulous)
%
% Ouput F -- M x 1 array of force along members
% U -- N x 3 array of Node displacement vectors
% R -- N x 3 array of Reaction force vectors
%% History
% Original code by Hossein Rahami
% 17 Mar 2007 (Updated 13 Apr 2007)
% Frank McHugh 06 Sep 2012
function [F,U,R]=ST(D)
w=size(D.Re); % 3 x number of nodes
S=zeros(3*w(2)); % stiffness matrix is 3*(number of nodes) square matrix
U=1-D.Re; % U is displacement matrix [
% column index by node
% x , y , z by rows
% initialize U to 1 for non fixed nodes 0 for fixed
f=find(U); % f index in U of free nodes
for i=1:size(D.Con,2) % Loop through Connectors (members)
H=D.Con(:,i);
C=D.Coord(:,H(2))-D.Coord(:,H(1)); % C is vector for connector i
Le=norm(C); % Le length of connector i
T=C/Le; % T is unit vector for connector i
s=T*T'; % Member Siffness matrix is of form
% k * | s -s |
% | -s s | in global truss coordinates
G=D.E(i)*D.A(i)/Le; % G aka k stiffness constant of member = E*A/L
Tj(:,i)=G*T; % Stiffness vector of this member
e=[3*H(1)-2:3*H(1),3*H(2)-2:3*H(2)];
% indexes into Global Stiffness matrix S for this member
S(e,e)=S(e,e)+G*[s -s;-s s];
% add this members stiffness to stiffness matrix
end
U(f)=S(f,f)\D.Load(f); % solve for displacements of free nodes
% ie solve F = S * U for U where S is stiffness
% matrix.
F=sum(Tj.*(U(:,D.Con(2,:))-U(:,D.Con(1,:))));
%project displacement of each node pair on to member
% between
% f = Tj dot ( U2j - U1j ). Then sum over all contributing
% node pairs.
R=reshape(S*U(:),w); % compute forces at all nodes = S*U
R(f)=0; % zero free nodes leaving only reaction.
File 3:
function TP(D,U,Sc)
C=[D.Coord;D.Coord+Sc*U];
e=D.Con(1,:);
f=D.Con(2,:);
for i=1:6
M=[C(i,e);C(i,f); repmat(NaN,size(e))];
X(:,i)=M(:);
end
plot3(X(:,1),X(:,2),X(:,3),'k',X(:,4),X(:,5),X(:,6),'m');
axis('equal');
if D.Re(3,:)==1;
view(2);
end
When I run each file I get errors due to the inputs created from prevous files not transferring to the other m file. How do I connect these files so that they run smoothly and the outputs are turned to inputs for other files? Please be specific
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Anurag Agrawal el 31 de Mzo. de 2020
Editada: Anurag Agrawal el 31 de Mzo. de 2020
As you are using functions in your m-files, you can call the function (of your first m-file) then you can save it's output and then provide it to the second function.
>> [output1] = myFunction1(input);
>> [output2] = myFunction2(output1);
The above is a very simplistic example where I have two functions that both have one input and output parameter. The output of the first function is then passed in as the input to the second function.
In your case you can you can create one more .m file, say main.m and call your functions one by one
D = Data;
[F,U,R]=ST(D);
TP(D,U,Sc);
I hope this will help.
Refer this documentation to know about functions:
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Structural Analysis en Help Center y File Exchange.

### Etiquetas

Aún no se han introducido etiquetas.

### Community Treasure Hunt

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

Start Hunting!

Translated by