2-D Truss Analysis

19 vues (au cours des 30 derniers jours)
Jillian Franke
Jillian Franke le 21 Oct 2020
Commenté : Long Hoang Van le 20 Nov 2020
I have got my for loop to work which was my main issue but now when I try to display the unit vectors into command window using the fprintf my unit vectors all come out as zero. When I run my for loop they are not zero. I can't seem to figure out what is causing them to be zero in the fprintf
%.... Input problem data
nNodesP = 12;
nMembersP = 21;
NodeP = zeros(nNodesP, 3); %Initialize memory storage
MemberP = zeros(nMembersP, 2);
%.... Input node coordinates
NodeP(1,:) = [0,0,0];
NodeP(2,:) = [2,0,0];
NodeP(3,:) = [4,0,0];
NodeP(4,:) = [6,0,0];
NodeP(5,:) = [8,0,0];
NodeP(6,:) = [10,0,0];
NodeP(7,:) = [12,0,0];
NodeP(8,:) = [10,1.5,0];
NodeP(9,:) = [8,3,0];
NodeP(10,:) = [6,3,0];
NodeP(11,:) = [4,3,0];
NodeP(12,:) = [2,1.5,0];
%.... Input member connections
MemberP(1,:) = [1,2];
MemberP(2,:) = [2,3];
MemberP(3,:) = [3,4];
MemberP(4,:) = [4,5];
MemberP(5,:) = [5,6];
MemberP(6,:) = [6,7];
MemberP(7,:) = [7,8];
MemberP(8,:) = [8,9];
MemberP(9,:) = [9,10];
MemberP(10,:) = [10,11];
MemberP(11,:) = [11,12];
MemberP(12,:) = [1,12];
MemberP(13,:) = [2,12];
MemberP(14,:) = [2,11];
MemberP(15,:) = [3,11];
MemberP(16,:) = [3,10];
MemberP(17,:) = [4,10];
MemberP(18,:) = [5,10];
MemberP(19,:) = [5,9];
MemberP(20,:) = [6,9];
MemberP(21,:) = [6,8];
%% .. Use a for loop to compute the position vector between connected
%nodes, the distance between connected nodes, and to compute the unit
%vectors for the direction of every member. You can use the variable name
%"UnitVecP" for the unit vectors in the planar truss.
PosVecP = zeros(nMembersP, 3); %Initialize memory storage
UnitVecP = zeros(nMembersP, 3);
OppPosVecP = zeros(nMembersP, 3);
for j = 1 : nMembersP
SN = MemberP(j,1); %SN = start node
EN = MemberP(j,2); %EN = end node
PosVecP(j,:) = NodeP(EN,:)- NodeP(SN,:);
Length(j,:) = norm(PosVecP(j,:));
UniVecP(j,:) = PosVecP(j,:)/Length(j,:)
negUniVecP(j,:) = -UniVecP(j,:);
%Finish this section to compute the position vector, length, unit vector,
%and negative unit vector for each member in the truss.
end % for j (members)
%% .Create output for command window
fprintf('%s\n' , '----------------------------------------')
fprintf('%s\n' , '-------------Planar Truss---------------')
fprintf('%s\n' , '----------------------------------------')
for j = 1 : nNodesP
fprintf('%s%8i%8.3f%8.3f%8.3f\n',' Node: ',j, NodeP(j,:)')
end
fprintf('\n')
for j = 1 : nMembersP
fprintf('%s%8i%8.3f%8.3f%8.3f\n',' Unit Vector: ',j, UnitVecP(j,:)')
end
fprintf('\n\n\n')
  3 commentaires
Jillian Franke
Jillian Franke le 21 Oct 2020
How would I go about fixing this issue so they aren't zeros in the display window?
Long Hoang Van
Long Hoang Van le 20 Nov 2020
boolean matrix?

Connectez-vous pour commenter.

Réponses (1)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam le 21 Oct 2020
One t was missing in UniVctor:
%.... Input problem data
nNodesP = 12;
nMembersP = 21;
NodeP = zeros(nNodesP, 3); %Initialize memory storage
MemberP = zeros(nMembersP, 2);
%.... Input node coordinates
NodeP(1,:) = [0,0,0];
NodeP(2,:) = [2,0,0];
NodeP(3,:) = [4,0,0];
NodeP(4,:) = [6,0,0];
NodeP(5,:) = [8,0,0];
NodeP(6,:) = [10,0,0];
NodeP(7,:) = [12,0,0];
NodeP(8,:) = [10,1.5,0];
NodeP(9,:) = [8,3,0];
NodeP(10,:) = [6,3,0];
NodeP(11,:) = [4,3,0];
NodeP(12,:) = [2,1.5,0];
%.... Input member connections
MemberP(1,:) = [1,2];
MemberP(2,:) = [2,3];
MemberP(3,:) = [3,4];
MemberP(4,:) = [4,5];
MemberP(5,:) = [5,6];
MemberP(6,:) = [6,7];
MemberP(7,:) = [7,8];
MemberP(8,:) = [8,9];
MemberP(9,:) = [9,10];
MemberP(10,:) = [10,11];
MemberP(11,:) = [11,12];
MemberP(12,:) = [1,12];
MemberP(13,:) = [2,12];
MemberP(14,:) = [2,11];
MemberP(15,:) = [3,11];
MemberP(16,:) = [3,10];
MemberP(17,:) = [4,10];
MemberP(18,:) = [5,10];
MemberP(19,:) = [5,9];
MemberP(20,:) = [6,9];
MemberP(21,:) = [6,8];
%% .. Use a for loop to compute the position vector between connected
%nodes, the distance between connected nodes, and to compute the unit
%vectors for the direction of every member. You can use the variable name
%"UnitVecP" for the unit vectors in the planar truss.
PosVecP = zeros(nMembersP, 3); %Initialize memory storage
UnitVecP = zeros(nMembersP, 3);
OppPosVecP = zeros(nMembersP, 3);
for j = 1 : nMembersP
SN = MemberP(j,1); %SN = start node
EN = MemberP(j,2); %EN = end node
PosVecP(j,:) = NodeP(EN,:)- NodeP(SN,:);
Length(j,:) = norm(PosVecP(j,:));
UnitVecP(j,:) = PosVecP(j,:)/Length(j,:);
negUniVecP(j,:) = -UniVecP(j,:);
%Finish this section to compute the position vector, length, unit vector,
%and negative unit vector for each member in the truss.
end % for j (members)
%% .Create output for command window
fprintf('%s\n' , '----------------------------------------')
fprintf('%s\n' , '-------------Planar Truss---------------')
fprintf('%s\n' , '----------------------------------------')
for j = 1 : nNodesP
fprintf('%s%8i%8.3f%8.3f%8.3f\n',' Node: ',j, NodeP(j,:)')
end
fprintf('\n')
for j = 1 : nMembersP
fprintf('%s%8i%8.3f%8.3f%8.3f\n',' Unit Vector: ',j, UnitVecP(j,:)')
end
fprintf('\n\n\n')
  1 commentaire
Jillian Franke
Jillian Franke le 21 Oct 2020
Thank you!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Structural Analysis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by