# Free MATLAB Code for Flexural Design of R.C. Sections According to EC2

In this post, I am going to present an extremely simplified MATLAB code for carrying out flexural design of reinforced concrete beams (rectangular or flanged) according to Eurocode 2. Before you can use this code, you must carry out yourÂ analysis and obtain your design forces and moments. You can just copy the code and paste on your MATLAB script. There are no external functions to be called for the program.

% ANALYSIS AND DESIGN OF RECTANGULAR AND FLANGED BEAMS PER EUROCODE 2
% THIS PROGRAM WILL CALCULATE THE AREA OF REINFORCEMENT REQUIRED, AND ALSO DO THE DEFLECTION VERIFICATION USING THE DEEMED TO SATISFY RULES OF EC2

clc
disp(â€˜THIS PROFORMA WAS WRITTEN BY O.U.R UBANIâ€™)
disp(â€˜ANALYSIS AND DESIGN OF BEAMS PER EUROCODE 2â€™)

% INPUT MATERIAL PROPERTIES
Fck = input(â€˜Enter the grade of concrete (N/mm^2)FckÂ  = â€˜);
Fyk = input(â€˜Enter the yield strength of steel (N/mm^2)Fyk = â€˜);

% INPUT DESIGN MOMENT
MEd = input(â€˜Enter the ultimate design moment (KNm) MEd = â€˜);

% INPUT SECTION AND DESIGN PROPERTIES
h = input(â€˜Enter the depth of beam (mm)h = â€˜);
b = input(â€˜Enter the effective flange width of the beam (mm)b = â€˜);
bw = input(â€˜Enter the beam width (mm)bw = â€˜);
Cc = input(â€˜Enter concrete cover (mm) = â€˜);
dr = input(â€˜Enter the diameter of reinforcement (mm) = â€˜);
dl = input(â€˜Enter the diameter of links = â€˜);

% CALCULATION OF EFFECTIVE DEPTH

disp(â€˜Effective depth d (mm)â€™)
d = h-Cc-(dr/2)-dl % Effective depth
disp(â€˜Depth of reinforcement from the face of concreteâ€™)
do = Cc+dl+(dr/2)

% ANALYSIS FOR INTERNAL STRESSES
ko = 0.167;
k = (MEd*10^6)/(Fck*b*d^2)
if k>ko
disp(â€˜Since k > ko, Compression reinforcement is requiredâ€™)
Mcd = (Fck*b*d^2*(k-ko))*10^(-6)
As2 = (Mcd*10^6)/(0.87*Fyk*(d-do))
z = 0.5*d*(1+sqrt(1-3.53*ko))
As1 = ((ko*Fck*b*d^2)/(0.87*Fyk*z))+ As2
else
disp(â€˜Since k < ko, No Compression reinforcement is requiredâ€™)
disp(â€˜Lever arm (la)â€™)
la = 0.5+sqrt(0.25-0.882*k)
if la>0.95
disp(â€˜Since la > 0.95,â€™)
la = 0.95
else
la = 0.5+sqrt(0.25-0.882*k)
end
As1 =(MEd*10^6)/(0.87*Fyk*la*d)
end

% MINIMUM AREA OF STEEL REQUIRED
fctm = 0.3*(Fck^(2/3)) %MEAN TENSILE STRENGTH OF CONCRETE (TABLE 3.1 EC2)
ASmin = 0.26*(fctm/Fyk)*bw*d
if ASmin < 0.0013*bw*d
ASmin = 0.0013*bw*d
end
if As1<ASmin
As1 = ASmin
else
disp(â€˜Since As1 > Asmin, provide As1 which is the area of steel requiredâ€™)
end

Asprov1 = input(â€˜Enter area of tension steel provided (mm^2) = â€˜);
Asprov2 = input(â€˜Enter area of compression steel provided if any (mm^2) = â€˜);

% CHECK FOR DEFLECTION

disp(â€˜DO YOU WANT TO CHECK FOR DEFLECTION?â€™)
G = input(â€˜ENTER (1) FOR YES OR (0) FOR NO = â€˜);
if G == 1;
Â  Â  disp(â€˜CHECK FOR DEFLECTIONâ€™)Â
disp(â€˜BASIC SPAN/EFFECTIVE DEPTH RATIO (K)â€™)
disp(â€˜CANTILEVER = 0.4â€™)
disp(â€˜SIMPLY SUPPORTED = 1.0â€™)
disp(â€˜SIMPLY SUPPORTED AND FIXED AT ONE END = 1.3â€™)
disp(â€˜FIXED AT BOTH ENDS = 1.5â€™)
K = input(â€˜Enter the selected value of k = â€˜);
L = input(â€˜Enter the deflection critical length of the member (mm) = â€˜);
Â
Fs = (310*Fyk*As1)/(500*Asprov1)
disp(â€˜Bs = 310/Fsâ€™)
Bs = 310/Fs
disp(â€˜P is the reinforcement ratio in the section (Asprov1)/(b*d)â€™)
P = (Asprov1)/(b*d)
disp(â€˜Po = sqrt(Fck)/1000â€™)
Po = sqrt(Fck)/1000
P1 = (Asprov2)/(b*d)
ifÂ
Â  P <= Po
Â  I_deflection = K*(11+(1.5*sqrt(Fck)*(Po/P)) + 3.2*sqrt(Fck)*((Po/P)-1)^1.5)
else
Â  Â  I_deflection = K*(11+(1.5*sqrt(Fck)*(Po/(P-P1))) + 3.2*sqrt(Fck)*((Po/P)-1)^1.5)
end
CV = input(â€˜Is the beam is flanged? (1) for YES and (0) for NO = â€˜)
if CV == 1
disp(â€˜S is the ratio of beff/bwâ€™)
S = b/bw
Â  bn = (11-(b/bw))/10
Â
Â  if S >= 3.0;
Â  Â K_deflection = Bs*0.8* I_deflection
else
Â  Â K_deflection = Bs*bn* I_deflection
Â  end
Â  Â if L>7000
Â  Â  Limiting_deflection = (7000/L)*K_deflection
else
Â  Â  Limiting_deflection = Â K_deflection
end
Â  end
else
Â  Limiting_deflection = Â  Bs*I_deflection
end
Actual_deflection = L/d
ifÂ
Limiting_deflection > Actual_deflection
Â  Â  disp(â€˜Deflection is satisfactoryâ€™)
else
Â  Â  disp(â€˜DEFLECTION IS NOT SATISFACTORY !!!!! Increase depth of beam, or increase area of steel, or both. Then rerun proformaâ€™)

end

2.0 MATLAB CODE FOR SHEAR DESIGN ACCORDING TO EC2

clc
disp(â€˜SHEAR DESIGN ACCORDING TO EC2â€²)
disp(â€˜THIS PROFORMA WAS WRITTEN BY O.U.R. UBANIâ€™)

% MATERIALS PROPERTIES
Fck = input(â€˜Enter the grade of concrete (N/mm^2) = â€˜);
Fyk = input(â€˜Enter the yield strength of steel (N/mm^2) = â€˜);

VEd = input(â€˜Enter the value of shear force at ULS (KN) = â€˜);

% SECTION PROPERTIES
h = input(â€˜Enter the depth of beam (mm) = â€˜);
bw = input(â€˜Enter the beam width (mm) = â€˜);
Cc = input(â€˜Enter concrete cover (mm) = â€˜);
dr = input(â€˜Enter the diameter of reinforcement (mm) = â€˜);
dl = input(â€˜Enter the diameter of links = â€˜)
d = h-Cc-(dr/2)-dl % Effective depth
do = Cc+dl+(dr/2)

% CALCULATION OF THE SHEAR CAPACITY OF THE SECTION WITH NO SHEAR REINFORCEMENT
Â
Asprov1= input(â€˜Enter the area of steel provided in the shear zone (mm^2) = â€˜) % The reinforcement must exceed the design anchorage length by at least the effective depth
Crd = 0.12
k1= 1+sqrt(200/d)
if k1>2
k1=2
end
disp(â€˜Reinforcement ratioâ€™)
P1 = (Asprov1/(bw*d))
if P1>0.02
P1 = 0.02

end

% THIS SECTION IS TO BE CONSIDERED IF THERE IS AXIAL FORCE IN THE SECTION
disp(â€˜Axial force in the sectionâ€™)
N = input(â€˜Enter the value of AXIAL FORCE IF ANY(+VE FOR COMP, AND -VE FOR TENSION)(kN) = â€˜)
disp(â€˜Axial stress in the section (Ds)â€™)
Ds = (N*1000)/(bw*h)
if Ds > (0.2*0.85*Fck)/1.5
Ds = (0.2*0.85*Fck)/1.5
end
k2 = 0.15;
disp(â€˜Minimum shear stress in the section (N/mm^2)â€™)
Vmin = 0.035*k1^(1.5)*sqrt(Fck)
disp(â€˜Concrete resistance shear stress (VRd) (N/mm^2)â€™)
VRdQ = ((Crd*k1)*(100*P1*Fck)^(1/3)*(bw*d))/1000 % SHEAR FORCE CONTRIBUTION
VRdN = ((k2*Ds)*(bw*d))/1000 % AXIAL FORCE CONTRIBUTION
VRd = VRdQ + VRdN % TOTAL SHEAR RESISTANCE
if VRd < ((Vmin+(k2*Ds))*(b*d))/1000
VRd = ((Vmin+(k2*Ds))*(b*d))/1000
end
if VRd>VEd
disp(â€˜Since VRd > VEdâ€™)
disp(â€˜NO SHEAR REINFORCEMENT REQUIRED, PROVIDE NOMINAL LINKSâ€™)
else
if VRd<VEd
disp(â€˜SinceÂ  VRd < VEdâ€™)
disp(â€˜SHEAR REINFORCEMENT REQUIRED, CALCULATE COMPRESSION STRUT CAPACITYâ€™)
disp(â€˜Assume strut angle (thetha) = 21.8 deg, cot(thetha)= 2.5â€™)
thetha = 21.8
V1 = 0.6*(1-(Fck/250))
disp(â€˜Design compressive strength of concrete (fcd) (N/mm^2)â€™)
fcd = 0.567*Fck
z = 0.9*d
disp(â€˜Maximum capacity of compression strut (KN)â€™)
VRDmax = ((b*z*V1*fcd)/(2.9))/1000
if VRDmax > VEd
disp(â€˜Since VRDmax > VEdâ€™)
disp(â€˜OK! Calculate diameter and spacing of linksâ€™)
else
disp(â€˜Since VRDmax > VEd, it means we need a higher strut angle (beta)â€™)
disp(â€˜By calculating the strut angleâ€™)
disp(â€˜Shear stress at the section (N/mm^2)â€™)
v = (VEd*1000)/(b*d)
beta = (0.5)*asind((v)/(0.153*Fck*(1-(Fck/250))))
if beta>45
disp(â€˜Since beta < 45 deg, SECTION INADEQUATE FOR SHEAR, INCREASE DEPTH !!!!!â€™)
Â Â  else
disp(â€˜The ratio of Area of steel/spacing of linksâ€™)
end
end
end
Area_of_legs = input(â€˜Enter the area of number of legs selected = â€˜)
Spacing = input(â€˜Enter the spacing = â€˜)
disp(â€˜CHECKâ€™)
T = Area_of_legs/Spacing
disp(â€˜Shear reinforcement is okâ€™)
else
disp(â€˜Increase area of steel, or reduce spacingâ€™)
end
endÂ Â