File size: 6,957 Bytes
a8ced59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
% Simple RC-SRP Script Calculator (Inline Configuration)
% Author: Rembrant Oyangoren Albeos
% Year: 2026

clear; clc;

%% --- CONFIGURABLE SETTINGS ---
% Modify these variables directly before running the script.

% Concrete and Steel Properties
fc = 4000;      % Concrete compressive strength f_c' (psi)
fy = 60000;     % Steel yield strength f_y (psi)

% Beam Dimensions
b = 12;         % Beam width b (in)
h = 20;         % Beam height h (in)
cover = 2.5;    % Cover distance to extreme tension layer (in)

% Layer 1 (Bottom) Reinforcement
n_bars1 = 4;    % Number of bars in layer 1
a_bar = 0.79;   % Area per bar (in^2)

% Layer 2 (Top) Reinforcement
% Set n_bars2 to 0 for a Single Layer computation.
n_bars2 = 0;    % Number of bars in layer 2
spacing = 0;    % Spacing between layers (in)

% Output Option
show_output = true; % Set to true to display calculation output in Command Window

%% --- CALCULATION LOGIC ---

if show_output
    disp(' ');
    disp('--- CALCULATION OUTPUT ---');
    
    % Basic constants
    fc_ksi = fc / 1000;
    fy_ksi = fy / 1000;
    Es_ksi = 29000;
    E_cu = 0.003;
    
    % Calculate beta1 factor
    beta1 = 0.85;
    if fc > 4000
        beta1 = 0.85 - 0.05 * ((fc - 4000) / 1000);
    end
    beta1 = max(beta1, 0.65);
    
    % Minimum steel factor
    limit_val = 3 * sqrt(fc);
    As_min_factor = max(limit_val, 200);
    
    % Determine if it's Single or Double Layer automatically
    if n_bars2 == 0
        layer_type = 'Single Layer Singly Reinforced';
        
        % --- SINGLE LAYER CALCULATION ---
        d = h - cover;
        As = n_bars1 * a_bar;
        
        disp(['1. Effective depth (d): ', num2str(d), ' in']);
        disp(['   Area of steel (A_s): ', num2str(As), ' in^2']);
        
        % Force and depth of compression block
        T = As * fy_ksi;
        disp(['2. Tension force (T, assuming yield): ', num2str(T), ' kips']);
        
        a = T / (0.85 * fc_ksi * b);
        c = a / beta1;
        disp(['3. Compression block depth (a): ', num2str(a), ' in']);
        disp(['   Neutral axis depth (c): ', num2str(c), ' in']);
        
        % Check if steel actually yields
        eps_y = fy_ksi / Es_ksi;
        eps_s = ((d - c) / c) * E_cu;
        disp(['4. Yield strain (eps_y): ', num2str(eps_y)]);
        disp(['   Steel strain (eps_s): ', num2str(eps_s)]);
        
        if eps_s >= eps_y
            disp('   Status: Steel yielded. Assumption OK.');
        else
            disp('   Status: Steel did NOT yield. Assumption failed.');
        end
        
        % Calculate Nominal Moment
        Mn = T * (d - a/2) / 12;
        disp(['5. Nominal Moment (M_n): ', num2str(Mn), ' kip-ft']);
        
        % Check minimum code requirement for steel
        As_min = (As_min_factor / fy) * b * d;
        disp(['6. Minimum steel (A_s,min): ', num2str(As_min), ' in^2']);
        if As >= As_min
            disp('   Status: A_s >= A_s,min. OK.');
        else
            disp('   Status: A_s < A_s,min. Does not meet minimum requirement.');
        end
        
        % Compute reduction factor
        eps_t = eps_s;
        if eps_t >= 0.005
            phi = 0.90;
        elseif eps_t <= 0.002
            phi = 0.65;
        else
            phi = 0.65 + (eps_t - 0.002) * (250/3);
        end
        
        phi_Mn = phi * Mn;
        disp(['7. Reduction factor (phi): ', num2str(phi)]);
        disp(['8. Design Moment (phi*M_n): ', num2str(phi_Mn), ' kip-ft']);
        
    else
        layer_type = 'Double Layer Singly Reinforced';
        
        % --- DOUBLE LAYER CALCULATION ---
        As1 = n_bars1 * a_bar;
        As2 = n_bars2 * a_bar;
        As = As1 + As2;
        
        dist1 = cover;
        dist2 = cover + spacing;
        
        % Calculate centroid of steel
        g = (As1 * dist1 + As2 * dist2) / As;
        d = h - g;
        d_t = h - cover;
        
        disp(['1. Centroid distance (g): ', num2str(g), ' in']);
        disp(['   Effective depth (d): ', num2str(d), ' in']);
        disp(['   Area of steel (A_s): ', num2str(As), ' in^2']);
        
        % Force and depth of compression block
        T = As * fy_ksi;
        a = T / (0.85 * fc_ksi * b);
        c = a / beta1;
        disp(['2. Tension force (T, assuming yield): ', num2str(T), ' kips']);
        disp(['3. Compression block depth (a): ', num2str(a), ' in']);
        disp(['   Neutral axis depth (c): ', num2str(c), ' in']);
        
        % Check if steel yields
        eps_y = fy_ksi / Es_ksi;
        eps_s = ((d - c) / c) * E_cu;
        disp(['4. Yield strain (eps_y): ', num2str(eps_y)]);
        disp(['   Steel strain (eps_s): ', num2str(eps_s)]);
        
        if eps_s < eps_y
            disp('   Status: Over-reinforced section. Assumption Failed.');
            disp('   Solving exact c using quadratic method...');
            
            % Use quadratic for exact answer if not yielded
            A_quad = 0.85 * fc_ksi * b * beta1;
            B_quad = As * Es_ksi * E_cu;
            C_quad = -1 * As * Es_ksi * E_cu * d;
            
            roots_c = roots([A_quad, B_quad, C_quad]);
            c = max(roots_c(roots_c > 0));
            a = beta1 * c;
            
            disp(['   Exact Neutral axis (c): ', num2str(c), ' in']);
            disp(['   Exact Compression block (a): ', num2str(a), ' in']);
            
            T = As * Es_ksi * ((d - c)/c) * E_cu;
            disp(['   Exact Tension force (T): ', num2str(T), ' kips']);
        else
            disp('   Status: Steel yielded. Assumption OK.');
        end
        
        % Calculate Nominal Moment
        Mn = T * (d - a/2) / 12;
        disp(['5. Nominal Moment (M_n): ', num2str(Mn), ' kip-ft']);
        
        % Check minimum code requirement for steel
        As_min = (As_min_factor / fy) * b * d;
        disp(['6. Minimum steel (A_s,min): ', num2str(As_min), ' in^2']);
        if As >= As_min
            disp('   Status: A_s >= A_s,min. OK.');
        else
            disp('   Status: A_s < A_s,min. Does not meet minimum requirement.');
        end
        
        % Compute reduction factor using extreme tension layer
        eps_t = ((d_t - c) / c) * E_cu;
        if eps_t >= 0.005
            phi = 0.90;
        elseif eps_t <= 0.002
            phi = 0.65;
        else
            phi = 0.65 + (eps_t - 0.002) * (250/3);
        end
        
        phi_Mn = phi * Mn;
        disp(['7. Extreme tension strain (eps_t): ', num2str(eps_t)]);
        disp(['   Reduction factor (phi): ', num2str(phi)]);
        disp(['8. Design Moment (phi*M_n): ', num2str(phi_Mn), ' kip-ft']);
    end
    
    disp(' ');
    disp(['CONCLUSION: The calculated section is [', layer_type, '].']);
end