Debugging for a truss problem
Mostra commenti meno recenti
So I'm having a debugging problem and i cant seem to figure out how to solve it.
Here is my data for the truss set up:
function D=DataP
% Definition of Data
% Nodal Coordinates
Coord=[0 0 0;3 0 0;6 0 0;9 0 0;12 0 0;15 0 0;18 0 0;3 5 0;15 5 0;6 10 0;9 10 0;12 10 0];
% Connectivity
Con=[1 2;2 3;3 4;4 5;5 6;6 7;7 9;9 12;12 11;11 10;10 8;8 2;8 3;10 3;10 4;11 4;12 4;12 5;9 5;9 6];
% Definition of Degree of freedom (free=0 & fixed=1); for 2-D trusses the last column is equal to 1
Re=zeros(size(Coord));Re=[1 1 1;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;0 1 1;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0];
% Definition of Nodal loads %%%%%%%%
Load=zeros(size(Coord));Load([2],:)=[0 150 0];
Here is my program to figure out the forces, recations, and displacement. This is were the problem is occuring: The problem is occuring is line 18.
function [F,U,R]=ST(D)
w=size(D.Re);
S=zeros(3*w(2));
U=1-D.Re;
f=find(U);
Tj=zeros(3, 10);
for i=1:size(D.Con,2)
H=D.Con(:,i);
C=D.Coord(:,H(2))-D.Coord(:,H(1));
Le=norm(C);
T=C/Le;
s=T*T';
G=D.E(i)*D.A(i)/Le;
Tj(:,i)=G*T;
e=[3*H(1)-2:3*H(1),3*H(2)-2:3*H(2)];
S(e,e)=S(e,e)+G*[s -s;-s s];
end
U(f)=S(f,f)./D.Load(f); *%%This is line 18*
F=sum(Tj.*(U(:,D.Con(2,:))-U(:,D.Con(1,:))));
R=reshape(S*U(:),w);R(f)=0;
The error that is coming up is Index exceeds matrix dimensions.
Error in ST (line 18) U(f)=S(f,f)./D.Load(f);
I also have another set of code not sure if there is a problem there yet or not since it fails at this point.
function TP(D,U,Sc)
C=[D.Coord;D.Coord+Sc*U];
e=D.Con(1,:);
f=D.Con(2,:);
for i=1:6
M=[C(i,e);
C(i,f);
repmat(NaN,size(e))];
X(:,i)=M(:);
end
plot3(X(:,1),X(:,2),X(:,3),'k',X(:,4),X(:,5),X(:,6),'m');
axis('equal');
if D.Re(3,:)==1;
view(2);
end
Then I have a line of code to run it all.
D=DataP;
[F,U,R]=ST(D)
TP(D,U,20)
2 Commenti
Image Analyst
il 12 Lug 2016
What is DataP? What is the value of f when it errors? What is the value of D.load when it errors. You might think you can't, but you can get all of these answers from the debugger. But we can't run your code unless we have DataP because that is the first line of your program.
Arthur Blessing
il 13 Lug 2016
Risposte (0)
Categorie
Scopri di più su Structural Analysis in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!