Parker/Gambrel Truss Algorithm- undefined function or variable 'm'
1 次查看(过去 30 天)
显示 更早的评论
I kept getting a 'preallocating for speed error' on line 73 for r(m).
I solved that issue by setting:
r(m) = zeros; %(before the for loop function)
NOW I'm getting an 'undefined function or variable 'm' error' on line 65.
NEED to make this code plot a Parker/Gambrel truss like in the picture:

what is wrong with my code?
clear, clf, clc
choice1=menu('Truss Program would like you to enter truss dimensions manually and define its dimensions?'...
,'Enter Dimensions Manually');
switch choice1
case 1
J=input('Please enter the number of joints:\n');
M=(2*J)-3; %Joint-member relationship for a simple, planar truss.
C=zeros(J,M); %Preallocates the connection matrix
x=zeros(J,1); %Preallocates the joint position vectors
y=zeros(J,1); %Prompts user for coordinates for joint positions through a loop
for j=1:J
promptx=sprintf('Please enter the x coordinate of joint %d in FEET:\n',j);
x(j)=input(promptx);
prompty=sprintf('Now enter the y coordinate of joint %d in FEET:\n',j);
y(j)=input(prompty);
end
%Builds the connection matrix from a loop of queries asking the
%user which members are connected to each joint.
cnct{1,J}=[]; %Each cell in 'cnct' contains the indices of the corresponding row in connection matrix 'C' that are to be assigned the value of 1.
for j=1:J
str=sprintf('How many members are connected to joint %d?\n',j);
choice2=menu(str,'1','2','3','4','5','6');
cnct{j}=zeros(choice2,1);
for i=1:choice2
rem=choice2-(i-1);
str2=sprintf('Which members? (%d members remaining for joint %d.)\n',rem,j);
cnct{j}(i)=input(str2);
end
C(j,cnct{j})=1;
end
end
%--------------------DEFINE SUPPORT AND LOAD MATRICES---------------------%
tstart=tic;
%Creates support force connection matrix
Sx=zeros(J,3);
Sy=zeros(J,3);
Sx(1,1)=1;
Sy(1,2)=1;
Sy(J,3)=1;
%Creates a load vector describing the location and strength of the
%load on the truss
L=zeros(2*J,1);
choice3=menu('Would you like to set a load at a joint?','Set a Load');
switch choice3
case 1
Lj=input('What number joint will the load be placed at?\n');
F=input('Please enter the value of the load in Newtons: \n');
L(J+Lj)=F;
end
%---------------------CONSTRUCT EQUILIBRIUM EQUATIONS---------------------%
%Preallocation
deltax=zeros(M,1);
deltay=zeros(M,1);
ux=zeros(M,1);
uy=zeros(M,1);
Ax=zeros(J,M);
Ay=zeros(J,M);
r=zeros(1,M);
%Calculates coefficients for matrix A.
for m=1:M
vec=find(C(:,m));
deltax(m)=abs(x(vec(2))-x(vec(1)));
deltay(m)=abs(y(vec(2))-y(vec(1)));
r(m)= magnitude(deltax(m),deltay(m));
ux(m)=deltax(m)/r(m);
uy(m)=deltay(m)/r(m);
if x(vec(1))<x(vec(2))
Ax(vec(1),m)=ux(m);
Ax(vec(2),m)=-ux(m);
else
Ax(vec(1),m)=-ux(m);
Ax(vec(2),m)=ux(m);
end
if y(vec(1))<y(vec(2))
Ay(vec(1),m)=uy(m);
Ay(vec(2),m)=-uy(m);
else
Ay(vec(1),m)=-uy(m);
Ay(vec(2),m)=uy(m);
end
end
A=[Ax Sx;Ay Sy]; %Creates matrix A
T=A\L; %Solves equilibrium equations
%--------------------------ANALYSIS OF RESULTS----------------------------%
f=plottruss(x,y,C,critmember,Lj);
set(f,'Visible','on','Name','NameTest')
11 个评论
Daniel M
2019-10-22
You didn't post the functions that you're calling. So I get an error on line 7 for an undefined function PrintSpaceTrussNodeCoordinates.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structural Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!