For statement with "if" in it not calculating all values
Mostrar comentarios más antiguos
Hi,
I have a code to calculate Moving Reference Influence Lİnes and Response of a beam with 3 axle loads. It has 2 loops and one if statement inside the inner loop. The last "elseif" is actually the general formulation for all cases while other if and elseif statements are for stating some special cases. But the "j" loop turns zero values for j=2 and 3 columns of "delta_x" and "spr_x". And finally I have the wrong result for resp_x. I'll be glad if someone could help. Thanks..
Gvw = [21600]; % Gross Vehicle Weight
N = 20; % No. beam elements
Lb = 13; % Length of the beam
% MR-IL & Response
na=3; % number of axles
d1=[1.95 4.03 6.16];
x1=zeros(N+1,1);
AAB=zeros(N+1,na); ABC=zeros(N+1,na); ACD=zeros(N+1,na);
delta_x=zeros(N+1,na); spr_x=zeros(N+1,na);
resp_x=zeros(N+1,1);
b1=zeros(N+1,na); a1 = zeros(N+1,na);
k1=340000; k2=340000; % [assumed-kN/m]
for i=1:N+1 %along beam length
x1(i)=(i-1).*(Lb/N);
for j=1:na % for all 3 d distances
if x1(i)< d1(1) %before the first axle (P1) arrives
spr_x(i,:)=0; % support deflection
delta_x(i,:)=0; %beam cont. to ML-IL
elseif x1(i)== d1(1) % when P1 arrives
b1(i,j)=Lb-x1(i)+d1(j);
a1(i,j)=x1(i)-d1(j);
spr_x(i,1)=(((b1(i,1)./ (k1.*Lb))-(a1(i,1)./(k2.*Lb))).*((Lb-x1(i))./Lb)) + (a1(i,1)./(k2.*Lb)); % support deflections' contribution to MR-IL
spr_x(i,2)=0; spr_x(i,3)=0; % Support defl. cont: only P1 arrived.
delta_x(i,1)=0; delta_x(i,2)=0; delta_x(i,3)=0; %beam cont. to ML-IL
elseif d1(1)<x1(i)<d1(2) % P2 hasn't arrived yet.
b1(i,j)=Lb-x1(i)+d1(j);
a1(i,j)=x1(i)-d1(j);
spr_x(i,1)=(((b1(i,1)./ (k1.*Lb))-(a1(i,1)./(k2.*Lb))).*((Lb-x1(i))./Lb)) + (a1(i,1)./(k2.*Lb)); % support deflections' contribution to MR-IL
spr_x(i,2)=0; spr_x(i,3)=0; % Support defl. cont: only P1 arrived.
AAB(i,1)=(x1(i)-d1(1)).^3.*(Lb-x1(i)+d1(1)).*(Lb-x1(i))./(3*Lb^2);
ABC(i,1)=d1(1).*((Lb-x1(i)).*(x1(i)-d1(1)).*( 2.*(Lb-x1(i)+d1(1)).*(x1(i)-d1(1))+(Lb-x1(i)+d1(1)).*x1(i) +(x1(i)-d1(1)).*(Lb-x1(i)) + 2.*x1(i).*(Lb-x1(i))))./(6.*Lb^2); % Area of the 2nd triangle of the BM diagram
ACD(i,1)=x1(i).*(Lb-x1(i)).^3.*(x1(i)-d1(1))./(3.*Lb^2);
delta_x(i,j)=-(((AAB(i,j)+ABC(i,j)+ACD(i,j))./(EI/1000)) + spr_x(i,j)); % only P1 has a beam cont. to MR-IL.
elseif d1(2)<x1(i)<d1(3)% P3 hasn't arrived yet.
b1(i,j)=Lb-x1(i)+d1(j);
a1(i,j)=x1(i)-d1(j);
AAB(i,1)=(x1(i)-d1(1)).^3.*(Lb-x1(i)+d1(1)).*(Lb-x1(i))./(3*Lb^2);
ABC(i,1)=d1(1).*((Lb-x1(i)).*(x1(i)-d1(1)).*( 2.*(Lb-x1(i)+d1(1)).*(x1(i)-d1(1))+(Lb-x1(i)+d1(1)).*x1(i) +(x1(i)-d1(1)).*(Lb-x1(i)) + 2.*x1(i).*(Lb-x1(i))))./(6.*Lb^2); % Area of the 2nd triangle of the BM diagram
ACD(i,1)=x1(i).*(Lb-x1(i)).^3.*(x1(i)-d1(1))./(3.*Lb^2);
delta_x(i,j)=-(((AAB(i,j)+ABC(i,j)+ACD(i,j))./(EI/1000)) + spr_x(i,j));
AAB(i,2)=(x1(i)-d1(2)).^3.*(Lb-x1(i)+d1(2)).*(Lb-x1(i))./(3*Lb^2); % Area of the 1st triangle of the BM diagram
ABC(i,2)=d1(2).*((Lb-x1(i)).*(x1(i)-d1(2)).*( 2.*(Lb-x1(i)+d1(2)).*(x1(i)-d1(2))+(Lb-x1(i)+d1(2)).*x1(i) +(x1(i)-d1(2)).*(Lb-x1(i)) + 2.*x1(i).*(Lb-x1(i))))./(6.*Lb^2); % Area of the 2nd triangle of the BM diagram
ACD(i,2)=x1(i).*(Lb-x1(i)).^3.*(x1(i)-d1(2))./(3.*Lb^2); % Area of the 3rd triangle of the BM diagram
delta_x(i,j)=-(((AAB(i,j)+ABC(i,j)+ACD(i,j))./(EI/1000)) + spr_x(i,j));
delta_x(i,3)=0;% P3 has no beam cont. yet.
spr_x(i,1)=(((b1(i,1)./ (k1.*Lb))-(a1(i,1)./(k2.*Lb))).*((Lb-x1(i))./Lb)) + (a1(i,1)./(k2.*Lb));
spr_x(i,2)=(((b1(i,2)./ (k1.*Lb))-(a1(i,2)./(k2.*Lb))).*((Lb-x1(i))./Lb)) + (a1(i,2)./(k2.*Lb));
spr_x(i,3)=0; % Only P1 and P2 are on the beam.
elseif d1(3)< x1(i)<=Lb
b1(i,j)=Lb-x1(i)+d1(j);
a1(i,j)=x1(i)-d1(j);
spr_x(i,j)=(((b1(i,j)./ (k1.*Lb))-(a1(i,j)./(k2.*Lb))).*((Lb-x1(i))./Lb)) + (a1(i,j)./(k2.*Lb));
AAB(i,j)=(x1(i)-d1(j)).^3.*(Lb-x1(i)+d1(j)).*(Lb-x1(i))./(3*Lb^2);
ABC(i,j)=d1(j).*((Lb-x1(i)).*(x1(i)-d1(j)).*( 2.*(Lb-x1(i)+d1(j)).*(x1(i)-d1(j))+(Lb-x1(i)+d1(j)).*x1(i) +(x1(i)-d1(j)).*(Lb-x1(i)) + 2.*x1(i).*(Lb-x1(i))))./(6.*Lb^2); % Area of the 2nd triangle of the BM diagram
ACD(i,j)=x1(i).*(Lb-x1(i)).^3.*(x1(i)-d1(j))./(3.*Lb^2);
delta_x(i,j)=-(((AAB(i,j)+ABC(i,j)+ACD(i,j))./(EI/1000)) + spr_x(i,j));
end
resp_x(i)=resp_x(i)+(Gvw/100).*delta_x(i,j);
end
end
% ---------------------------------- Plot --------------------------------
% Response plot
figure; hold on; title('Response');
plot(x1,resp_x,'b','LineWidth',2.0);
hold on
set(gca,'FontSize',12);
hold off
grid on
xlabel('x - distance[m]'); ylabel('Response[m]');
glad if any one could help..
1 comentario
Voss
el 6 de En. de 2022
One thing is you have to break up multiple conditions like this:
d1(1)<x1(i)<d1(2)
into this:
d1(1)<x1(i) && x1(i)<d1(2)
Respuestas (1)
Sinem Tola
el 7 de En. de 2022
0 votos
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!