Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Nodes give the 3-D locations of nodal points of the truss and Connectivities des

ID: 3838449 • Letter: N

Question

Nodes give the 3-D locations of nodal points of the truss and Connectivities describe whichnodes are connected together. Write a MATLAB program to read the data from such a file and plot the geometry of thestructure as shown in Figures below. Note: Read all the nodes information into an array and allconnectivity information into an array and then finally plot all the elements in the connectivity.

The information below was a file that was suppose ot be uploaded and use to complete the task.

Nodes
-----
-1 -1 0
1 -1 0
1 1 0
-1 1 0
-0.5 -0.5 1
0.5 -0.5 1
0.5 0.5 1
-0.5 0.5 1
Connectivities
--------------
1 5
1 6
5 2
2 6
2 7
6 3
3 7
3 8
7 4
4 8
4 5
1 8
5 7
6 8
5 6
6 7
7 8
8 5

Explanation / Answer

clg % Clear graphics window

clear all % Clear all variables

clc % Clear command window

hold off % No hold on the graphics window

%

% This script needs the following scripts to run

% matcut.m --> trims a matrix

% veccut.m --> trims a vector

% femtruss.m --> FEA for trusses

% It also needs the following input files

% node.dat --> nodal data

% elem.dat --> element data

% forces.dat --> force data

% disp.dat -->data of displacement boundary condition

% Read in nodal and element connectivity data from

% files: nodes.dat and elem.dat

load node.dat

load elem.dat

%

load forces.dat

load dispbc.dat

%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% PRE-PROCESSING

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Identify the number of nodes, X and Y Coordinates of the nodes

NNODE = size(node,1);

nx = node(:,2);

ny = node(:,3);

%

% form an element connectivity

array,

% the cross-section and Young's modulus arrays.

NELEM = size(elem,1);

ncon = elem(:,[2 3]);

A = elem(:,4);

E = elem(:,5);

%

F = zeros(2*NNODE,1); % Initialization

Nforce = size(forces,1);

for i = 1:Nforce,

dof = (forces(i,2)-1)*2 + forces(i,3);

F(dof) = forces(i,4);

end

%

% Displacement boundary conditions

Nfix = size(dispbc,1);

j = 0;

for i = 1:Nfix,

j = j + 1; dispID(j) = (dispbc(i,2)-1)*2+dispbc(i,3);

end

dispID = sort(dispID);

%

% Compute the lengths of the elements

for ie=1:NELEM,

eye = ncon(ie,1);

jay = ncon(ie,2);

L(ie) = sqrt ( (nx(jay) - nx(eye))^2 + (ny(jay) - ny(eye))^2 );

end

%

%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% SOLUTION

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[U,R,Fint,Kglobal,SE] =

femtruss(A,L,E,nx,ny,ncon,NELEM,NNODE,F,dispID);

%

%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% POST-PROCESSING

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Plotting

for ip=1:NELEM,

pt1 = ncon(ip,1); pt2 = ncon(ip,2);

dx1 = U(2*(pt1-1)+1);

dy1 = U(2*(pt1-1)+2);

dx2 = U(2*(pt2-1)+1);

dy2 = U(2*(pt2-1)+2);

TorC = Fint(ip,5);

%

% Plot undeformed only

plot([nx(pt1) nx(pt2)], [ny(pt1) ny(pt2)],'--y');

hold on

plot([nx(pt1) nx(pt2)], [ny(pt1) ny(pt2)],'oy');

if TorC == 1

plot([nx(pt1)+dx1 nx(pt2)+dx2], [ny(pt1)+dy1 ny(pt2)+dy2],'-r');

elseif TorC == -1

plot([nx(pt1)+dx1 nx(pt2)+dx2], [ny(pt1)+dy1 ny(pt2)+dy2],'-c');

else

plot([nx(pt1)+dx1 nx(pt2)+dx2], [ny(pt1)+dy1 ny(pt2)+dy2],'-w');

end

end

xlabel('X');

ylabel('Y');

axis('equal');

legend('--y','Undeformed','yo','Node','-r','Tensile stress','-c',...

'Compressive stress','-w','No stress');

===================end of truss.m======================

===================start of matcut.m===================

function D = mcut(C,i)

[m,n] = size(C);

d1 = C(1:i-1,1:i-1);

d2 = C(1:i-1,i+1:n);

d3 = C(i+1:m,1:i-1);

d4 = C(i+1:m,i+1:n);

D = [d1 d2; d3 d4];

===================end of matcut.m=====================

===================start of veccut.m===================

function D = veccut(C,i)

[m,n] = size(C);

if m == 1

d1 = C(1:i-1);

d2 = C(i+1:n);

D = [d1 d2];

end

if n == 1

d1 = C(1:i-1);

d2 = C(i+1:m);

D = [d1; d2];

end

===================end of veccut.m===================

===================start of femtruss.m===============

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Inputs:

% ncon --> A matrix containing the nodal-connectivity of

% all the elements

% F --> A vector contating the applied external forces

% dispID --> A vector containing the

% displacement boundary condition information

%

% Outputs:

% u --> The displacements of all the dof

% Rdisp --> The reaction forces at the dof which are

% specified to be fixed

% P --> A matrix containing the X and Y internal

% reaction forces at the two

% ends of each element, and flag that tells you %

if the element is in tension (1), compression %

(-1) or no stress (0).

%

function [u,Rdisp,P,Ksing,SE] = femtruss(Ae, Le, Ee, nx, ny, ncon,

NELEM, NNODE, F, dispID)

K = zeros(2*NNODE,2*NNODE); % Initialize global stiffness

matrix

for ie=1:NELEM,

eye = ncon(ie,1);

jay = ncon(ie,2);

% Form the transformation matrix, Lambda.

L = Le(ie);

A = Ae(ie);

E = Ee(ie);

lox = (nx(jay)-nx(eye))/L; mox = (ny(jay)-ny(eye))/L;

6.13

loy = -mox; moy = lox;

Lambda = [ lox mox 0 0 ; ...

0 0 lox mox ];

k = [ 1 -1; -1 1 ]; % Local element stiffness matrix

k = k*(A*E/L);

klocal = Lambda' * k * Lambda;

id1 = 2*(eye-1) + 1;

id2 = id1 + 1;

id3 = 2*(jay-1) + 1;

id4 = id3 + 1;

K(id1,id1) = K(id1,id1) + klocal(1,1);

K(id1,id2) = K(id1,id2) + klocal(1,2);

K(id2,id1) = K(id2,id1) + klocal(2,1);

K(id2,id2) = K(id2,id2) + klocal(2,2);

K(id1,id3) = K(id1,id3) + klocal(1,3);

K(id1,id4) = K(id1,id4) + klocal(1,4);

K(id2,id3) = K(id2,id3) + klocal(2,3);

K(id2,id4) = K(id2,id4) + klocal(2,4);

K(id3,id1) = K(id3,id1) + klocal(3,1);

K(id3,id2) = K(id3,id2) + klocal(3,2);

K(id4,id1) = K(id4,id1) + klocal(4,1);

K(id4,id2) = K(id4,id2) + klocal(4,2);

K(id3,id3) = K(id3,id3) + klocal(3,3);

K(id3,id4) = K(id3,id4) + klocal(3,4);

K(id4,id3) = K(id4,id3) + klocal(4,3);

K(id4,id4) = K(id4,id4) + klocal(4,4);

end

% Store unlaltered K as Ksing before applying the boundary conditions.

Ksing = K;

%det(K)

%inv(K);

%pause

% Imposing displacement boundary conditions

% ------------------------------------------

% dispID array contains the dof which are assigned zero values.

[sm,sn] = size(dispID);

6.14

Ndbc = sn;

for nd=1:Ndbc,

K = matcut(K,dispID(nd)-nd+1);

F = veccut(F,dispID(nd)-nd+1);

end

% To solve for unknown displacements.

U = inv(K)*F;

SE = 0.5*U'*K*U;

u = zeros(2*NNODE,1);

for iu=1:Ndbc,

u(dispID(iu)) = 12345.12345;

end

iuc = 0;

for iu=1:2*NNODE,

if u(iu) == 12345.12345

iuc = iuc+1;

else

u(iu) = U(iu-iuc);

end

end

for iu=1:Ndbc,

u(dispID(iu)) = 0;

end

dx = zeros(1,NNODE);

dy = zeros(1,NNODE);

for iu=1:NNODE,

dx(iu) = u(2*(iu-1)+1);

dy(iu) = u(2*(iu-1)+2);

end

R = Ksing*u;

Rdisp = zeros(1,Ndbc);

for iu=1:Ndbc,

Rdisp(iu) = R(dispID(iu));

end

%-------------------------------------------

%-------------------------------------------

M = zeros(NNODE,1);

for ie=1:NELEM,

eye = ncon(ie,1);

jay = ncon(ie,2);

L = Le(ie); A = Ae(ie);

lox = (nx(jay)-nx(eye))/L; mox = (ny(jay)-ny(eye))/L;

loy = -mox; moy = lox;

Lambda = [ lox mox 0 0 ; ...

0 0 lox mox ];

k = [ 1 -1; -1 1 ];

k = k*(A*E/L);

klocal = Lambda' * k * Lambda;

id1 = 2*(eye-1) + 1;

id2 = id1 + 1;

id3 = 2*(jay-1) + 1;

id4 = id3 + 1;

ulocal = [u(id1) u(id2) u(id3) u(id4)];

Rint = klocal*ulocal';

P(ie,1) = Rint(1);

P(ie,2) = Rint(2);

P(ie,3) = Rint(3);

P(ie,4) = Rint(4);

nxd1 = nx(eye) + u(id1);

nyd1 = ny(eye) + u(id2);

nxd2 = nx(jay) + u(id3);

nyd2 = ny(jay) + u(id4);

Ld = sqrt( (nxd2-nxd1)^2 + (nyd2-nyd1)^2 );

if Ld > L P(ie,5) = 1; else P(ie,5) = -1; end

if Ld==L P(ie,5) = 0; end

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote