File size: 6,896 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
% Simple RC-SRP Script Calculator

clear; clc;

disp('--- Simple RC-SRP Calculator ---');
disp('Follow the steps to enter the given variables.');

% Get inputs from the user through the command window
fc = input('Enter concrete compressive strength f_c'' (psi): ');
fy = input('Enter steel yield strength f_y (psi): ');
b = input('Enter beam width b (in): ');
h = input('Enter beam height h (in): ');
cover = input('Enter cover distance to extreme tension layer (in): ');

n_bars = input('Enter total number of bars: ');
a_bar = input('Enter area per bar (in^2): ');

% Ask if there's a second layer
double_layer_ans = input('Is this a double layer reinforcement? (yes/no): ', 's');

if strcmpi(double_layer_ans, 'yes')
    layer_type = 'Double Layer Singly Reinforced';
    n_bars1 = input('Enter number of bars in layer 1 (bottom): ');
    n_bars2 = input('Enter number of bars in layer 2 (top): ');
    spacing = input('Enter spacing between layers (in): ');
else
    layer_type = 'Single Layer Singly Reinforced';
end

% Ask user if they want to calculate and show output
show_output = input('Ready to calculate and show the output? (yes/no): ', 's');

if strcmpi(show_output, 'yes')
    disp(' ');
    disp('--- CALCULATION OUTPUT ---');
    
    % Identify the type of calculated section
    disp(['Type of section: ', layer_type]);
    disp(' ');
    
    % 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);
    
    if strcmpi(double_layer_ans, 'no')
        % --- SINGLE LAYER CALCULATION ---
        d = h - cover;
        As = n_bars * a_bar;
        
        disp(['1. Effective depth (d): ', num2str(d), ' in']);
        disp(['2. Area of steel (A_s): ', num2str(As), ' in^2']);
        
        % Force and depth of compression block
        T = As * fy_ksi;
        disp(['3. Tension force (T, assuming yield): ', num2str(T), ' kips']);
        
        a = T / (0.85 * fc_ksi * b);
        c = a / beta1;
        disp(['4. 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(['5. 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(['6. Nominal Moment (M_n): ', num2str(Mn), ' kip-ft']);
        
        % Check minimum code requirement for steel
        As_min = (As_min_factor / fy) * b * d;
        disp(['7. Minimum steel (A_s,min): ', num2str(As_min), ' in^2']);
        if As >= As_min
            disp('   Status: A_s >= A_s,min. OK.');
        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(['8. Reduction factor (phi): ', num2str(phi)]);
        disp(['9. Design Moment (phi*M_n): ', num2str(phi_Mn), ' kip-ft']);
        
    else
        % --- 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(['2. 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(['3. Tension force (T, assuming yield): ', num2str(T), ' kips']);
        disp(['4. 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(['5. 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(['6. Nominal Moment (M_n): ', num2str(Mn), ' kip-ft']);
        
        % Check minimum code requirement for steel
        As_min = (As_min_factor / fy) * b * d;
        disp(['7. Minimum steel (A_s,min): ', num2str(As_min), ' in^2']);
        if As >= As_min
            disp('   Status: A_s >= A_s,min. OK.');
        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(['8. Extreme tension strain (eps_t): ', num2str(eps_t)]);
        disp(['   Reduction factor (phi): ', num2str(phi)]);
        disp(['9. Design Moment (phi*M_n): ', num2str(phi_Mn), ' kip-ft']);
    end
else
    disp('Calculation stopped. Have a great day!');
end