msa.m File error in Line 4 "H=D.Con(:,i);C=D.Coord(:,H(2))-D.Coord(:,H(1));e=[6*H(1)-5:6*H(1),6*H(2)-5:6*H(2)];c=D.be(i);". Comes up with "Index in position 2 exceeds array bounds (must not exceed 1)." and an error with no solution.
Show older comments
This is the script file with the error:
function [Q,V,R]=MSA(D)
m=D.m;n=D.n;Ni=zeros(12,12,m);S=zeros(6*n);Pf=S(:,1);Q=zeros(12,m);Qfi=Q;Ei=Q;
for i=1:m
H=D.Con(:,i);C=D.Coord(:,H(2))-D.Coord(:,H(1));e=[6*H(1)-5:6*H(1),6*H(2)-5:6*H(2)];c=D.be(i);
[a,b,L]=cart2sph(C(1),C(3),C(2));ca=cos(a);sa=sin(a);cb=cos(b);sb=sin(b);cc=cos(c);sc=sin(c);
r=[1 0 0;0 cc sc;0 -sc cc]*[cb sb 0;-sb cb 0;0 0 1]*[ca 0 sa;0 1 0;-sa 0 ca];T=kron(eye(4),r);
co=2*L*[6/L 3 2*L L];x=D.A(i)*L^2;y=D.Iy(i)*co;z=D.Iz(i)*co;g=D.G(i)*D.J(i)*L^2/D.E(i);
K1=diag([x,z(1),y(1)]);K2=[0 0 0;0 0 z(2);0 -y(2) 0];K3=diag([g,y(3),z(3)]);K4=diag([-g,y(4),z(4)]);
K=D.E(i)/L^3*[K1 K2 -K1 K2;K2' K3 -K2' K4;-K1 -K2 K1 -K2;K2' K4 -K2' K3];
w=D.w(:,i)';Qf=-L^2/12*[6*w/L 0 -w(3) w(2) 6*w/L 0 w(3) -w(2)]';Qfs=K*T*D.St(e)';
A=diag([0 -0.5 -0.5]);B(2,3)=1.5/L;B(3,2)=-1.5/L;W=diag([1,0,0]);Z=zeros(3);M=eye(12);p=4:6;q=10:12;
switch 2*H(3)+H(4)
case 0;B=2*B/3;M(:,[p,q])=[-B -B;W Z;B B;Z W];case 1;M(:,p)=[-B;W;B;A];case 2;M(:,q)=[-B;A;B;W];
end
K=M*K;Ni(:,:,i)=K*T;S(e,e)=S(e,e)+T'*Ni(:,:,i);Qfi(:,i)=M*Qf;Pf(e)=Pf(e)+T'*M*(Qf+Qfs);Ei(:,i)=e;
end
V=1-(D.Re|D.St);f=find(V);V(f)=S(f,f)\(D.Load(f)-Pf(f));R=reshape(S*V(:)+Pf,6,n);R(f)=0;V=V+D.St;
for i=1:m
Q(:,i)=Ni(:,:,i)*V(Ei(:,i))+Qfi(:,i);
end
This is a msa.m file provided by https://au.mathworks.com/matlabcentral/fileexchange/27012-matrix-structural-analysis ,
And this is the script file used with the msa file in it:
% Units; Kg & m
m=35;
n=20;
%Coordinates=[0 0;1 0;3 0;4 0;3 2;5 2;0 2];
coord=[0 0;50 0;400 0;450 0;25 30;
425 30;0 60;50 60;75 60;150 60;
225 60;300 60;375 60;400 60;450 60;
75 160;150 160;225 160;300 160;400 160];
Coord(:,3)=0;
Con=[1 2;1 5;1 7;2 5;2 8;
7 5;7 9;5 8;7 16;9 16;
9 10;10 16;16 17;10 17;10 11;
17 18;11 17;11 18;11 12;
11 19;18 19;12 19;12 13;
12 20;19 20;13 20;13 15;
15 20;3 14;3 6;3 4;4 6;
4 15;6 14;6 15];
Con(:,3:4)=0;
Re=ones(n,6);
Re(1:m,1:2)=0;
Re(1,1:2)=[0 1];
Re(4,1:2)=[0 1];
Load=zeros(n,6);
Load(18,2)=-5;
w=zeros(m,3);
E=ones(1,m)*2.1e6;nu=0.3;G=E/(2*(1+nu));
A=ones(1,m)*100;Iz=ones(1,m)*1000;Iy=ones(1,m)*1000;J=ones(1,m)*50;
St=zeros(n,6);
be=zeros(1,m);
D=struct('m',m,'n',n,'Coord',Coord','Con',Con','Re',Re','Load',Load',...
'w',w','E',E','G',G','A',A','Iz',Iz','Iy',Iy','J',J','St',St','be',be'); % A transpose is done at this point
[Q,V,R]=MSA(D)
for mm=1:m
TrussForce(D,Q,mm)
end
MSAPlot2(D,Q,V,R)
Answers (0)
Categories
Find more on MATLAB Report Generator 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!