Don't know how to make the loop works with variable

조회 수: 1 (최근 30일)
Ahmed Sayed
Ahmed Sayed 2020년 1월 19일
댓글: Walter Roberson 2020년 1월 20일
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
Ahmed Sayed
Ahmed Sayed 2020년 1월 20일
Thank you, replacing it does work and its better than the loop.
But still having the problem of Mn3 is 1x1 instead of being 1x16 double matrix
Walter Roberson
Walter Roberson 2020년 1월 20일
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.)

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2020년 1월 19일
It says
Unrecognized function or variable 'Sxt'.
Error in test (line 5)
if (Sxt/Sxc >= 0.7)
so that means that before that line, you need to define Sxt, Sxc, Fy, and any other variables that have not been defined.
  댓글 수: 15
Ahmed Sayed
Ahmed Sayed 2020년 1월 20일
First of all I am so sorry about all the mess & all the effort I am putting you all through.
I defined most of the variables in the begining of the code
the purpose of this code is to compute nominal moment (Mn) vs length between points that are either braced against lateral displacemnt or twist (Lb)
In order to calculate Mn there are 3 equations each depends on the value of Lb
I named them Mn1, Mn2 and Mn3 each (Lp>Lb) ,(Lp<Lb<Lr) ,(Lb > Lr) respectively
so my intend which probably I put in a totally wrong way is that only in the case of Lb > Lr to calculate R2 and Mn3
if (Iyc/Iy <= 0.23)
to take value of R1 = 1
value of Torsion constant J = 0
especially that the condition if (Iyc/Iy <= 0.23) to take the value of R1 = 1 but without J = 0 is used to calculate R1 and Mn2.
My other thing is how can I make Mn3 a 16 element vector like Mn2
I am so sorry against that most of the questions are totally amateur and beginner levels.
And thank you so much guys for helping me around with all the mess
Walter Roberson
Walter Roberson 2020년 1월 20일
You should probably have a vector of R1 and vector of J, one for each entry in Lb, and you should probably be using logical indexing to do your calculations
mask = lcy./ly < 0.23;
R1(mask) = 1;
J(mask) = 0;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by