gettrussdata2D error
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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');
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!