You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Don't know how to make the loop works with variable
1 view (last 30 days)
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
Ahmed Sayed
on 20 Jan 2020
what I wanted to do is only while calculating R2 in the case of Iyc/Iy <= 0.23
to take both variables R1 = 1 and J = 0
I might have put it in a wrong way in the code
Ahmed Sayed
on 20 Jan 2020
thank you, Walter
here is the code after the modifications added by Image Analyst.
But do you have any idea why In my case to make it take into consideration that Mn3 is 1x16 double matrix not only Mn2, as it is considering Mn3 as 1x1
sorry that I keep asking lots.
And again thank you so much
clc
clear all
close all
%INPUT PARAMETERS
%----------------
%bf1 = Upper Flange width
%tf1 = Thickness of the Upper Flange
%hw = Height of the web
%tw = Thickness of the web
%bf2 = Bottom Flange width
%tf2 = Thickness of the Bottom Flange
%A = Area of Section
%E = Modolus of Elasticity of Steel
%Fy = Yield Strength of Steel
%CALCULATION OF THE NEUTRAL AXIS
%-------------------------------
bf1 = 250;
tf1 = 12;
hw = 500;
tw = 8;
bf2 = 250;
tf2 = 12;
%AREA OF THE SECTION, mm2
%-------------------
A = bf1*tf1+bf2*tf2+hw*tw;
%Steel Properties, MPa
%-------------------
E = 205000
Fy = 265
%Torsion Constant, mm4
%-------------------
J = ((bf1*tf1.^3)+(bf2*tf2.^3)+(hw*tw.^3))/3;
%Distance between the flange centroids, mm
%-------------------
h0 = hw+(tf1/2)+(tf2/2);
hc = 2*hw/2;
h = hw+tf1+tf2;
%Calculation of the Plastic Section Modulus, mm3
%--------------------------------
Zx = ((bf1*tf1)*(tf1+hw+tf2-tf1))+(0.25*tw*(tf1+hw+tf2-(2*tf1)).^2);
%CALCULATIONS OF THE NEUTRAL AXIS, mm
%--------------------------------
Xbar = (((bf1*tf1)*(0.5*bf1))+((hw*tw)*(0.5*bf2))+((bf2*tf2)*(0.5*bf2)))/A;
Ybar = (((bf1*tf1)*(tf2+hw+0.5*tf1))+((hw*tw)*(tf2+0.5*hw))+((bf2*tf2)*(0.5*tf2)))/A;
% CALCULATION OF SECOND MOMENT AREA, mm4
%----------------------------------
Ix = ((tw*hw.^3)/12)+((bf1*tf1.^3)/12)+((bf2*tf2.^3)/12)+((2*bf1*tf1)*((hw+tf1).^2)/4);
Iy = ((hw*tw.^3)/12)+((tf1*bf1.^3)/12)+((tf2*bf2.^3)/12);
% CALCULATION OF RADIUS OF GYRATION, mm
%----------------------------------
rx = sqrt(Ix/A);
ry = sqrt(Iy/A);
%SECTION MODULUS, mm3
%---------------
Sx = 2*Ix/(tf1+hw+tf2);
Sy = 2*Iy/bf1;
%CALCULATIONS FOR THE COMPRESSION FLANGE & TENSION FLANGE
%---------------
bfc = bf1;
tfc = tf1;
bft = bf2;
tft = tf2;
Ixc = bfc*(tfc.^3)/12;
Iyc = tfc*(bfc.^3)/12;
Sxc = 2*Ix/(tf1+hw+tf2);
Syc = 2*Iy/bf1;
Ixt = bft*(tft.^3)/12;
Iyt = tft*(bft.^3)/12;
Sxt = 2*Ix/(tf1+hw+tf2);
Syt = 2*Iy/bf2;
%CALCULATIONS FOR THE COMPRESSION FLANGE YIELDING & LOCAL BUCKLING
%---------------
aw = hc*tw/(bfc*tfc);
lambdaf = bfc/(2*tfc);
lambdaw = hc/tw;
for Kc = 4/sqrt(h/tw)
if (Kc >= 0.35) && (Kc <= 0.76)
disp('0.35 <= Kc <= 0.76')
Kc = 4/sqrt(h/tw);
elseif (Kc > 0.76)
disp('Kc > 0.76')
Kc = 0.76;
else
disp('Kc < 0.35');
Kc = 0.35;
end
end
%CALCULATIONS OF THE PLASTIC MOMENT
%---------------
Mp = Fy*Zx;
%CALCULATIONS OF THE YIELD MOMENT IN THE COMPRESSION FLANGE
%---------------
Myc = Fy*Sx;
%CALCULATIONS FOR THE EFFECTIVE RADIUS OF GYRATION FOR LTB FOR I-SHAPES
%WITH RECTANGULAR COMPRESSION FLANGE, mm
%---------------
rt = bfc/sqrt(12*(1+(aw/6)));
if (Iyc/Iy > 0.23)
R = Mp/Myc;
elseif (Iyc/Iy <= 0.23)
R = 1;
end
%CALCULATIONS OF THE NOMINAL MOMENT (Lb <= Lp)
Mn1 = R*Myc;
%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
%FOR DOUBLY SYMMETRIC COMPACT I-SHAPED MEMBERS AND COMPACT CHANNELS
%---------------
Lp = 1.76*ry*sqrt(E/Fy);
%CALCULATIONS OF THE LIMITING UNBRACED LENGTH FOR THE LIMIT STATE
%OF INELASTIC LATERAL TORSIONAL BUCKLING, mm
%FOR COMPACT AND NON COMPACT WEB I SHAPED MEMEBRS AND COMPACT CHANNELS
%---------------
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 = Mp/Myc;
elseif (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
fprintf('Mn1 = %f. Mn2 = %f. Mn3 = %f.\n', Mn1, Mn2, Mn3)
Mn = zeros(1, length(Lb));
for k = 1 : length(Lb)
if Lb(k) <= Lp
fprintf('Mn = Mn1 = %f. And Lb(%d) = %f.\n', Mn1 , k, Lb(k))
Mn(k) = Mn1;
elseif Lb(k) > Lp && Lb(k) <= Lr
fprintf('Mn = Mn2 = %f. And Lb(%d) = %f.\n', Mn2 (k) , k, Lb(k))
Mn(k) = Mn2(k);
elseif Lb(k) > Lr
fprintf('Mn = Mn3 = %f. And Lb(%d) = %f.\n', Mn3 , k, Lb(k))
Mn(k) = Mn3;
end
end
plot(Lb,Mn)
title('Lb vs. Mn', 'FontSize', 15);
xlabel('Mn', 'FontSize', 15);
ylabel('Lb', 'FontSize', 15);
grid on;
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
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
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
Image Analyst
on 19 Jan 2020
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 Comments
Ahmed Sayed
on 19 Jan 2020
Edited: Image Analyst
on 19 Jan 2020
Thank you for replying back
sorry I didnt put the whole code was trying to make it shorter
Here is the whole code:
%INPUT PARAMETERS
%----------------
%bf1 = Upper Flange width
%tf1 = Thickness of the Upper Flange
%hw = Height of the web
%tw = Thickness of the web
%bf2 = Bottom Flange width
%tf2 = Thickness of the Bottom Flange
%A = Area of Section
%E = Modolus of Elasticity of Steel
%Fy = Yield Strength of Steel
%CALCULATION OF THE NEUTRAL AXIS
%-------------------------------
prompt1 = 'What is the width of the upper flange in mm? ';
bf1 = input(prompt1);
prompt2 = 'What is the thickness of the upper flange in mm? ';
tf1 = input(prompt2);
prompt3 = 'What is the height of the web in mm? ';
hw = input(prompt3);
prompt4 = 'What is the thickness of the web in mm? ';
tw = input(prompt4);
prompt5 = 'What is the width of the lower flange in mm? ';
bf2 = input(prompt5);
prompt6 = 'What is the thickness of the lower flange in mm? ';
tf2 = input(prompt6);
fprintf('\n')
fprintf('\n')
%AREA OF THE SECTION, mm2
%-------------------
A = bf1*tf1+bf2*tf2+hw*tw;
%Steel Properties, MPa
%-------------------
E = 205000
Fy = 265
%Torsion Constant, mm4
%-------------------
J = ((bf1*tf1^3)+(bf2*tf2^3)+(hw*tw^3))/3;
%Distance between the flange centroids, mm
%-------------------
h0 = hw+(tf1/2)+(tf2/2);
hc = 2*hw/2;
h = hw+tf1+tf2;
%Calculation of the Plastic Section Modulus, mm3
%--------------------------------
Zx = ((bf1*tf1)*(tf1+hw+tf2-tf1))+(0.25*tw*(tf1+hw+tf2-(2*tf1))^2);
%CALCULATIONS OF THE NEUTRAL AXIS, mm
%--------------------------------
Xbar = (((bf1*tf1)*(0.5*bf1))+((hw*tw)*(0.5*bf2))+((bf2*tf2)*(0.5*bf2)))/A;
Ybar = (((bf1*tf1)*(tf2+hw+0.5*tf1))+((hw*tw)*(tf2+0.5*hw))+((bf2*tf2)*(0.5*tf2)))/A;
% CALCULATION OF SECOND MOMENT AREA, mm4
%----------------------------------
Ix = ((tw*hw^3)/12)+((bf1*tf1^3)/12)+((bf2*tf2^3)/12)+((2*bf1*tf1)*((hw+tf1)^2)/4);
Iy = ((hw*tw^3)/12)+((tf1*bf1^3)/12)+((tf2*bf2^3)/12);
% CALCULATION OF RADIUS OF GYRATION, mm
%----------------------------------
rx = sqrt(Ix/A);
ry = sqrt(Iy/A);
%SECTION MODULUS, mm3
%---------------
Sx = 2*Ix/(tf1+hw+tf2);
Sy = 2*Iy/bf1;
%CALCULATIONS FOR THE COMPRESSION FLANGE & TENSION FLANGE
%---------------
bfc = bf1;
tfc = tf1;
bft = bf2;
tft = tf2;
Ixc = bfc*(tfc^3)/12;
Iyc = tfc*(bfc^3)/12;
Sxc = 2*Ix/(tf1+hw+tf2);
Syc = 2*Iy/bf1;
Ixt = bft*(tft^3)/12;
Iyt = tft*(bft^3)/12;
Sxt = 2*Ix/(tf1+hw+tf2);
Syt = 2*Iy/bf2;
%CALCULATIONS FOR THE COMPRESSION FLANGE YIELDING & LOCAL BUCKLING
%---------------
aw = hc*tw/(bfc*tfc);
lambdaf = bfc/(2*tfc);
lambdaw = hc/tw;
for Kc = 4/sqrt(h/tw)
if (Kc >= 0.35) && (Kc <= 0.76)
disp('0.35 <= Kc <= 0.76')
Kc = 4/sqrt(h/tw);
elseif (Kc > 0.76)
disp('Kc > 0.76')
Kc = 0.76;
else
disp('Kc < 0.35');
Kc = 0.35;
end
end
%CALCULATIONS OF THE PLASTIC MOMENT
%---------------
Mp = Fy*Zx;
%CALCULATIONS OF THE YIELD MOMENT IN THE COMPRESSION FLANGE
%---------------
Myc = Fy*Sx;
%CALCULATIONS FOR THE EFFECTIVE RADIUS OF GYRATION FOR LTB FOR I-SHAPES
%WITH RECTANGULAR COMPRESSION FLANGE, mm
%---------------
rt = bfc/sqrt(12*(1+(aw/6)));
if (Iyc/Iy > 0.23)
R = Mp/Myc;
elseif (Iyc/Iy <= 0.23)
R = 1;
end
%CALCULATIONS OF THE NOMINAL MOMENT (Lb <= Lp)
Mn1 = R*Myc;
%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
%FOR DOUBLY SYMMETRIC COMPACT I-SHAPED MEMBERS AND COMPACT CHANNELS
%---------------
Lp = 1.76*ry*sqrt(E/Fy);
%CALCULATIONS OF THE LIMITING UNBRACED LENGTH FOR THE LIMIT STATE
%OF INELASTIC LATERAL TORSIONAL BUCKLING, mm
%FOR COMPACT AND NON COMPACT WEB I SHAPED MEMEBRS AND COMPACT CHANNELS
%---------------
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)
Image Analyst
on 19 Jan 2020
Can you make it easy for us and hard code in the values for those 6 parameters you ask for? I don't know what to enter.
Ahmed Sayed
on 19 Jan 2020
Edited: Ahmed Sayed
on 19 Jan 2020
clc
clear all
close all
%INPUT PARAMETERS
%----------------
%bf1 = Upper Flange width
%tf1 = Thickness of the Upper Flange
%hw = Height of the web
%tw = Thickness of the web
%bf2 = Bottom Flange width
%tf2 = Thickness of the Bottom Flange
%A = Area of Section
%E = Modolus of Elasticity of Steel
%Fy = Yield Strength of Steel
%CALCULATION OF THE NEUTRAL AXIS
%-------------------------------
bf1 = 250;
tf1 = 12;
hw = 500;
tw = 8;
bf2 = 250;
tf2 = 12;
%AREA OF THE SECTION, mm2
%-------------------
A = bf1*tf1+bf2*tf2+hw*tw;
%Steel Properties, MPa
%-------------------
E = 205000
Fy = 265
%Torsion Constant, mm4
%-------------------
J = ((bf1*tf1^3)+(bf2*tf2^3)+(hw*tw^3))/3;
%Distance between the flange centroids, mm
%-------------------
h0 = hw+(tf1/2)+(tf2/2);
hc = 2*hw/2;
h = hw+tf1+tf2;
%Calculation of the Plastic Section Modulus, mm3
%--------------------------------
Zx = ((bf1*tf1)*(tf1+hw+tf2-tf1))+(0.25*tw*(tf1+hw+tf2-(2*tf1))^2);
%CALCULATIONS OF THE NEUTRAL AXIS, mm
%--------------------------------
Xbar = (((bf1*tf1)*(0.5*bf1))+((hw*tw)*(0.5*bf2))+((bf2*tf2)*(0.5*bf2)))/A;
Ybar = (((bf1*tf1)*(tf2+hw+0.5*tf1))+((hw*tw)*(tf2+0.5*hw))+((bf2*tf2)*(0.5*tf2)))/A;
% CALCULATION OF SECOND MOMENT AREA, mm4
%----------------------------------
Ix = ((tw*hw^3)/12)+((bf1*tf1^3)/12)+((bf2*tf2^3)/12)+((2*bf1*tf1)*((hw+tf1)^2)/4);
Iy = ((hw*tw^3)/12)+((tf1*bf1^3)/12)+((tf2*bf2^3)/12);
% CALCULATION OF RADIUS OF GYRATION, mm
%----------------------------------
rx = sqrt(Ix/A);
ry = sqrt(Iy/A);
%SECTION MODULUS, mm3
%---------------
Sx = 2*Ix/(tf1+hw+tf2);
Sy = 2*Iy/bf1;
%CALCULATIONS FOR THE COMPRESSION FLANGE & TENSION FLANGE
%---------------
bfc = bf1;
tfc = tf1;
bft = bf2;
tft = tf2;
Ixc = bfc*(tfc^3)/12;
Iyc = tfc*(bfc^3)/12;
Sxc = 2*Ix/(tf1+hw+tf2);
Syc = 2*Iy/bf1;
Ixt = bft*(tft^3)/12;
Iyt = tft*(bft^3)/12;
Sxt = 2*Ix/(tf1+hw+tf2);
Syt = 2*Iy/bf2;
%CALCULATIONS FOR THE COMPRESSION FLANGE YIELDING & LOCAL BUCKLING
%---------------
aw = hc*tw/(bfc*tfc);
lambdaf = bfc/(2*tfc);
lambdaw = hc/tw;
for Kc = 4/sqrt(h/tw)
if (Kc >= 0.35) && (Kc <= 0.76)
disp('0.35 <= Kc <= 0.76')
Kc = 4/sqrt(h/tw);
elseif (Kc > 0.76)
disp('Kc > 0.76')
Kc = 0.76;
else
disp('Kc < 0.35');
Kc = 0.35;
end
end
%CALCULATIONS OF THE PLASTIC MOMENT
%---------------
Mp = Fy*Zx;
%CALCULATIONS OF THE YIELD MOMENT IN THE COMPRESSION FLANGE
%---------------
Myc = Fy*Sx;
%CALCULATIONS FOR THE EFFECTIVE RADIUS OF GYRATION FOR LTB FOR I-SHAPES
%WITH RECTANGULAR COMPRESSION FLANGE, mm
%---------------
rt = bfc/sqrt(12*(1+(aw/6)));
if (Iyc/Iy > 0.23)
R = Mp/Myc;
elseif (Iyc/Iy <= 0.23)
R = 1;
end
%CALCULATIONS OF THE NOMINAL MOMENT (Lb <= Lp)
Mn1 = R*Myc;
%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
%FOR DOUBLY SYMMETRIC COMPACT I-SHAPED MEMBERS AND COMPACT CHANNELS
%---------------
Lp = 1.76*ry*sqrt(E/Fy);
%CALCULATIONS OF THE LIMITING UNBRACED LENGTH FOR THE LIMIT STATE
%OF INELASTIC LATERAL TORSIONAL BUCKLING, mm
%FOR COMPACT AND NON COMPACT WEB I SHAPED MEMEBRS AND COMPACT CHANNELS
%---------------
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)
Image Analyst
on 19 Jan 2020
The error says
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.
Did you try it's suggestion of using dot caret?
Also, after you do that there are problems with this line
else if Lb > Lp && Lb <= Lr
did you really mean "else if" (highly unusual) or did you mean "elseif" (more likely)? And secondly, Lb is a 16 element row vector, not a single number, so "Lb > Lp && Lb <= Lr" is a logical vector of 16 true or false values. What is your intent there?
Ahmed Sayed
on 19 Jan 2020
Thank you so much when taking both the corrections it works perfectly but seems there is something I am defining wrong with the Lb
I dont want it to show if its a true or false matrix, I want it to calculate its value for each then draw that table from Lb=0:1000:15000 vs the calculated for Mn (which uses Lb to subtitute in it)
I dont know how to do it
Here is the code after fixing:
clc
clear all
close all
%INPUT PARAMETERS
%----------------
%bf1 = Upper Flange width
%tf1 = Thickness of the Upper Flange
%hw = Height of the web
%tw = Thickness of the web
%bf2 = Bottom Flange width
%tf2 = Thickness of the Bottom Flange
%A = Area of Section
%E = Modolus of Elasticity of Steel
%Fy = Yield Strength of Steel
%CALCULATION OF THE NEUTRAL AXIS
%-------------------------------
bf1 = 250;
tf1 = 12;
hw = 500;
tw = 8;
bf2 = 250;
tf2 = 12;
%AREA OF THE SECTION, mm2
%-------------------
A = bf1*tf1+bf2*tf2+hw*tw;
%Steel Properties, MPa
%-------------------
E = 205000
Fy = 265
%Torsion Constant, mm4
%-------------------
J = ((bf1*tf1.^3)+(bf2*tf2.^3)+(hw*tw.^3))/3;
%Distance between the flange centroids, mm
%-------------------
h0 = hw+(tf1/2)+(tf2/2);
hc = 2*hw/2;
h = hw+tf1+tf2;
%Calculation of the Plastic Section Modulus, mm3
%--------------------------------
Zx = ((bf1*tf1)*(tf1+hw+tf2-tf1))+(0.25*tw*(tf1+hw+tf2-(2*tf1)).^2);
%CALCULATIONS OF THE NEUTRAL AXIS, mm
%--------------------------------
Xbar = (((bf1*tf1)*(0.5*bf1))+((hw*tw)*(0.5*bf2))+((bf2*tf2)*(0.5*bf2)))/A;
Ybar = (((bf1*tf1)*(tf2+hw+0.5*tf1))+((hw*tw)*(tf2+0.5*hw))+((bf2*tf2)*(0.5*tf2)))/A;
% CALCULATION OF SECOND MOMENT AREA, mm4
%----------------------------------
Ix = ((tw*hw.^3)/12)+((bf1*tf1.^3)/12)+((bf2*tf2.^3)/12)+((2*bf1*tf1)*((hw+tf1).^2)/4);
Iy = ((hw*tw.^3)/12)+((tf1*bf1.^3)/12)+((tf2*bf2.^3)/12);
% CALCULATION OF RADIUS OF GYRATION, mm
%----------------------------------
rx = sqrt(Ix/A);
ry = sqrt(Iy/A);
%SECTION MODULUS, mm3
%---------------
Sx = 2*Ix/(tf1+hw+tf2);
Sy = 2*Iy/bf1;
%CALCULATIONS FOR THE COMPRESSION FLANGE & TENSION FLANGE
%---------------
bfc = bf1;
tfc = tf1;
bft = bf2;
tft = tf2;
Ixc = bfc*(tfc.^3)/12;
Iyc = tfc*(bfc.^3)/12;
Sxc = 2*Ix/(tf1+hw+tf2);
Syc = 2*Iy/bf1;
Ixt = bft*(tft.^3)/12;
Iyt = tft*(bft.^3)/12;
Sxt = 2*Ix/(tf1+hw+tf2);
Syt = 2*Iy/bf2;
%CALCULATIONS FOR THE COMPRESSION FLANGE YIELDING & LOCAL BUCKLING
%---------------
aw = hc*tw/(bfc*tfc);
lambdaf = bfc/(2*tfc);
lambdaw = hc/tw;
for Kc = 4/sqrt(h/tw)
if (Kc >= 0.35) && (Kc <= 0.76)
disp('0.35 <= Kc <= 0.76')
Kc = 4/sqrt(h/tw);
elseif (Kc > 0.76)
disp('Kc > 0.76')
Kc = 0.76;
else
disp('Kc < 0.35');
Kc = 0.35;
end
end
%CALCULATIONS OF THE PLASTIC MOMENT
%---------------
Mp = Fy*Zx;
%CALCULATIONS OF THE YIELD MOMENT IN THE COMPRESSION FLANGE
%---------------
Myc = Fy*Sx;
%CALCULATIONS FOR THE EFFECTIVE RADIUS OF GYRATION FOR LTB FOR I-SHAPES
%WITH RECTANGULAR COMPRESSION FLANGE, mm
%---------------
rt = bfc/sqrt(12*(1+(aw/6)));
if (Iyc/Iy > 0.23)
R = Mp/Myc;
elseif (Iyc/Iy <= 0.23)
R = 1;
end
%CALCULATIONS OF THE NOMINAL MOMENT (Lb <= Lp)
Mn1 = R*Myc;
%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
%FOR DOUBLY SYMMETRIC COMPACT I-SHAPED MEMBERS AND COMPACT CHANNELS
%---------------
Lp = 1.76*ry*sqrt(E/Fy);
%CALCULATIONS OF THE LIMITING UNBRACED LENGTH FOR THE LIMIT STATE
%OF INELASTIC LATERAL TORSIONAL BUCKLING, mm
%FOR COMPACT AND NON COMPACT WEB I SHAPED MEMEBRS AND COMPACT CHANNELS
%---------------
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)
Image Analyst
on 19 Jan 2020
Still not sure what you want to do, but maybe you should make that last if block inside a for loop over the 16 elements of Lb:
fprintf('Mn1 = %f. Mn2 = %f. Mn3 = %f.\n', Mn1, Mn2, Mn3)
Mn = zeros(1, length(Lb));
for k = 1 : length(Lb)
if Lb(k) <= Lp
fprintf('Mn = Mn1 = %f. And Lb(%d) = %f.\n', Mn1, k, Lb(k))
Mn(k) = Mn1;
elseif Lb(k) > Lp && Lb(k) <= Lr
fprintf('Mn = Mn2 = %f. And Lb(%d) = %f.\n', Mn2(k), k, Lb(k))
Mn(k) = Mn2(k);
elseif Lb(k) > Lr
fprintf('Mn = Mn3 = %f. And Lb(%d) = %f.\n', Mn3, k, Lb(k))
Mn(k) = Mn3;
end
end
plot(Lb,Mn)
title('Lb vs. Mn', 'FontSize', 15);
xlabel('Mn', 'FontSize', 15);
ylabel('Lb', 'FontSize', 15);
grid on;
Is that what you're looking for?
Ahmed Sayed
on 19 Jan 2020
Edited: Ahmed Sayed
on 19 Jan 2020
you are a life saver thats exactly what I wanted to do, just didn't know how.
I tired the code but I dont know why when I added the last bit, it miscalculate the Mn3 value (as shown in the figure as a constant value while in relaity it isnt); while if I use the same code and give it only one value for Lb (e.g. 15000 it would give Mn3 = 113495026)
I dont understand why it sees Mn1 and Mn3 as 1x1 matrix instead of 1x16 double
but again thank you so much for the effort and sorry I ask lots of questions
Image Analyst
on 20 Jan 2020
You're welcome. So if we're done here and this answers your question, what we like people to do is to click the link to "Accept this answer". It gives answerers "reputation points" for helping you.
Ahmed Sayed
on 20 Jan 2020
Edited: Ahmed Sayed
on 20 Jan 2020
It does totally answer it, but I am sorry again for the silly question
In my case How to make it take into consideration that Mn3 is 1x16 double matrix not only Mn2.
sorry that I keep asking lots.
And again thank you so much
Walter Roberson
on 20 Jan 2020
>> R1 = 1 & 'J = 0'
R1 =
1×5 logical array
1 1 1 1 1
That is going to throw off anything that depends upon R1. You probably need
R1 = 1;
J = 0;
Ahmed Sayed
on 20 Jan 2020
Thank you for replying back
Done that but it is still not fixing the problem.
Image Analyst
on 20 Jan 2020
What exactly is your intent when you do this:
if (Iyc/Iy <= 0.23)
R1 = 1 & 'J = 0';
end
Is it not to set R1 to 1, and J equal to zero, like Walter said?
When I ran your code, Mn3 was NOT a 16 element vector like Mn2.
It might help if you thoroughly document each line of code. If I had written this code, there would be a comment line before every 1 or 2 lines of code. Often, believe it or not, if you describe what you're doing in words, it will let you see what you're doing wrong. Plus it helps us to help you. Right now all I see is an alphabet soup mess of a program. So, since I have trouble following it, I can only have tunnel vision and examine one small chunk at a time. Hence I don't know if Mn, Mn1, Mn2, Mn3, etc are vectors or scalars. All I see is what they are and have no idea if that's what they're supposed to be or not.
Ahmed Sayed
on 20 Jan 2020
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
on 20 Jan 2020
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;
More Answers (0)
See Also
Categories
Find more on Logical 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)