Don't know how to make the loop works with variable
Show older comments
Sorry new to all of this.
Whenever I try using 'Lb' as a range (from 0 to 15000 with load step of 1000) that I want the program to calculate for each, errors keep showing, and it won't continue with the calculations.
Thanks in advance.
%CALCULATIONS OF THE LATERAL TORSIONAL BUCKLING
%---------------
Cb = 1;
Lb = 0:1000:15000;
if (Sxt/Sxc >= 0.7)
FL = 0.7*Fy;
elseif (Sxt/Sxc < 0.7)
if (Fy*Sxt/Sxc >= 0.5*Fy)
FL = Fy*Sxt/Sxc;
elseif (Fy*Sxt/Sxc < 0.5*Fy)
FL = 0.5*Fy;
end
end
%CALCULATIONS OF THE LIMITING LATERALLY UNBRACED LENGTH FOR THE LIMIT STATE
%OF YIELDING, mm
Lp = 1.76*ry*sqrt(E/Fy);
%CALCULATIONS OF THE LIMITING UNBRACED LENGTH FOR THE LIMIT STATE
%OF INELASTIC LATERAL TORSIONAL BUCKLING, mm
Lr = 1.95*rt*(E/FL)*sqrt((J/(Sxc*h0))+sqrt(((J/(Sxc*h0))^2)+(6.76*(FL/E)^2)));
%CALCULATIONS OF THE NOMINAL MOMENT (Lp < Lb <= Lr)
if (Iyc/Iy > 0.23)
R1 = Mp/Myc;
elseif (Iyc/Iy <= 0.23)
R1 = 1;
end
for Mn2 = Cb*((R1*Myc)-(((R1*Myc)-(FL*Sxc))*((Lb-Lp)/(Lr-Lp))))
if (Mn2 < R1*Myc)
disp('Mn2 = Cb*((R1*Myc)-((R1*Myc)-((FL*Sxc)*((Lb-Lp)/(Lr-Lp)))))')
Mn2 = Cb*((R1*Myc)-(((R1*Myc)-(FL*Sxc))*((Lb-Lp)/(Lr-Lp))));
elseif (Mn2 >= R1*Myc)
disp('Mn2 <= R1*Myc')
Mn2 = R1*Myc;
end
end
%CALCULATIONS OF THE NOMINAL MOMENT (Lb > Lr)
if (Iyc/Iy <= 0.23)
R1 = 1 & 'J = 0';
end
R2 = sqrt(1+(0.078*(J/(Sxc*h0))*(Lb/rt)^2));
for Mn3 = Cb*pi*pi*E*Sxc*R2/(Lb/rt)^2
if (Mn3 < R1*Myc)
disp('Mn3 = Cb*pi*pi*E*Sxc*R2/(Lb/rt)^2')
Mn3 = Cb*pi*pi*E*Sxc*R2/(Lb/rt)^2;
elseif (Mn3 >= R1*Myc)
disp('Mn3 = R1*Myc')
Mn3 = R1*Myc;
end
end
if Lb <= Lp
disp('Mn = Mn1')
Mn = Mn1
else if Lb > Lp && Lb <= Lr
disp('Mn = Mn2')
Mn=Mn2
else Lb > Lr
disp('Mn = Mn3')
Mn=Mn3
end
end
plot(Lb,Mn)
7 Comments
Walter Roberson
on 20 Jan 2020
R1 = 1 & 'J = 0';
What is the intention of that line?
Ahmed Sayed
on 20 Jan 2020
Walter Roberson
on 20 Jan 2020
R1 = 1;
J = 0;
maybe.
Ahmed Sayed
on 20 Jan 2020
Walter Roberson
on 20 Jan 2020
for Mn2 = Cb*((R1*Myc)-(((R1*Myc)-(FL*Sxc))*((Lb-Lp)/(Lr-Lp))))
if (Mn2 < R1*Myc)
disp('Mn2 = Cb*((R1*Myc)-((R1*Myc)-((FL*Sxc)*((Lb-Lp)/(Lr-Lp)))))')
Mn2 = Cb*((R1*Myc)-(((R1*Myc)-(FL*Sxc))*((Lb-Lp)/(Lr-Lp))));
elseif (Mn2 >= R1*Myc)
disp('Mn2 <= R1*Myc')
Mn2 = R1*Myc;
end
end
You have for Mn2 so Mn2 is a for loop variable. You are then altering that variable inside the for loop. That is not going to have the result you expect. You make the same mistake for Mn3 slightly further on.
What is the point of that code anyhow? If Mn2 is less than a certain value then you set Mn2 to... the exact same value it already was.
Perhaps you should be doing something like
Mn2 = min( Cb*((R1*Myc)-(((R1*Myc)-(FL*Sxc))*((Lb-Lp)/(Lr-Lp)))), R1*Myc );
Ahmed Sayed
on 20 Jan 2020
Walter Roberson
on 20 Jan 2020
Any time you have
for VARIABLE = ROW_VECTOR
end
then after the loop, VARIABLE will be a scalar (there is an obscure exception to this.)
Accepted Answer
More Answers (0)
Categories
Find more on Analysis and Verification 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!