gettrussdata2D error

22 views (last 30 days)
bashar hijazi
bashar hijazi on 12 May 2019
Commented: bashar hijazi on 12 May 2019
why i faces some error like(Error in Untitled5 (line 6)
[nodes, elems, C, A, bcs, loads] = gettrussdata2D(inpfilename);)
when i'm tried to apply this code in matlab
%2D Truss code
clear all; clc; close all; %clear all the existing variables (new start)
%Obtain the input file name from the user and Read input
inpfilename = uigetfile('ba.txt','select the input file');
[nodes, elems, C, A, bcs, loads] = gettrussdata2D(inpfilename);
Nel = size(elems,1);
Nnodes = size(nodes,1);
%Decide degrees of freedom + initialize matrices
alldofs = 1:2*Nnodes;
K = zeros(2*Nnodes);
u = zeros(2*Nnodes,1);
f = zeros(2*Nnodes,1);
%note:degrees of freedom correspodiing to node i are (2*(i-1)+1 2*(i-1)+2)
%boundary conditions
dofspec = [];
for ii = 1:size(bcs,1)
thisdof = 2*(bcs(ii,1)-1)+bcs(ii,2);
dofspec = [dofspec thisdof];
u(thisdof) = bcs(ii,3);
end
doffree = alldofs;
doffree(dofspec) = []; %delete specified dofs from all dofs
%nodal loads
for ii= 1:size(loads,1)
f(2*(loads(ii,1)-1)+loads(ii,2)) = loads(ii,3);
end
%initialize the global stiffness matrix
for iel = 1:Ne1
elnodes = elems( iel, 1:2);
nodexy = nodes(elnodes, :);
%get the elemnt stiffness matrix for the current element
[Kel] = TrussElement2D(nodexy, C(iel), A(IEL));
%ASSEMBLE THE ELEment stiffness matrix into the global stiffness matrix k
eldofs = 2*(elnodes(1)-1)+1:2*(elnodes(1)-1)+2;
K(eldofs,eldofs) = K(eldofs,eldofs) + Kel;
end
%solve
u(doffree) = K(doffree,doffree)\(f(doffree)-K(doffree,dofspace)*u(dofspec));
f(dofspec) = K(dofspec,:)*u;
format long
disp(['Displacement vector:']);u
disp(['Reactions (Force vector)']);f
%plot old shape
figure(1);hold on;
plot(nodes(:,1),nodes(:,2),'k.')
hold on;axis equal
for iel = 1:Nel
elnodes = elems(iel,1:2);
nodexy = nodes(elnodes, :);
plot(nodexy(:,1),nodexy(:,2),'k--')
end
%plot new shape
Magnification=20;
nodesnew = nodes + Magnification*reshape(u,2,Nnodes)';
plot(nodesnew(:,1),nodesnew(:,2),'o',...
'MarkerEdgeColor','k', 'MarkerFaceColor','r','MarkerSize',10)
hold on;axis equal;
for iel =1:Nel
elnodes = elems(iel, 1:2);
nodexy = nodesnew(elnodes, :);
plot(nodexy(:,1),nodexy(:,2),'K-','LineWidth',2)
end
title('Displacemnt');
  1 Comment
bashar hijazi
bashar hijazi on 12 May 2019
ba.txt
Nodes: (x,y)
0.0 4.0
3.0 4.0
0.0 4.0
3.0 4.0
6.0 4.0
Elements: (Node1 Node2), E A,
1 2 2ell le-5
1 3 2ell le-5
3 2 2ell le-5
2 4 2ell le-5
3 5 2ell le-5
3 4 2ell le-5
4 5 2ell le-5
BCs (Node_number dof specified_disp)
1 1 0
1 2 0
3 1 0
5 1 0
5 2 0
Nodal loads (Node_number dof
2 1 le4
4 2 -le4

Sign in to comment.

Answers (0)

Categories

Find more on Code Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!