This is a code that calculates the curvature and moment capacity of the given pre-stressed concrete beam section. I try returning two values from the
function: curvature and the total_moment. However, there is only one output which is the first element of the returning array. The code is:
function [curvature, moment] = axis_matlab(ec_top) %curv = 0;
%moment = 0;
%ec_top = 0.001;
h = 910; d = 795; ht = 180; b = 450; bw = 140; As = 1700; %fp = 1100;
fcu = 50; Ec = 12680 + 460 * fcu; Es = 200 * 1e3; ec0 = 2 * fcu / Ec; %ecu = 0.0038;
for c = 0:5e-3:h fs = Es * (c - d) * ec_top / c; Fs = fs * As * 1e-3; lis = linspace(0, c, c * 10); total_force = Fs; total_moment = Fs * (d - h / 2) * 1e-3 * -1; for i = 1:1:(length(lis) - 1) if lis(i) <= ht && lis(i) >= h - ht b_i = b; else b_i = bw; end h_i = lis(i + 1) - lis(i); y_i = (h / 2) - lis(i) + (h_i / 2); e_i = c - lis(i) + (h_i / 2); ec_i = ec_top * (c - e_i) / c; fc_i = fcu * ((2 * ec_i / ec0) - (ec_i / ec0) ^ 2); Fc_i = fc_i * h_i * b_i * 1e-3; M_i = Fc_i * y_i * 1e-3; total_force = total_force + Fc_i; moment = total_moment + M_i; curvature = ec_top / c; end if -1 < total_force && total_force < 1 break; end endend
"""
I ended up with this result:
>> axis_matlabans = 1.1270e-05
How do I get all return values from the function?
Additionally, I want to optimize this function as it iterates two many numbers to get the exact "c" value. Actually, the function was based on Python Language but I turned into Matlab document to get faster on running the code. As its known, there are different types for keeping the data (lists, tuples, sets and dicts.) in Python, to get the faster results, the list type must be adjusted properly. Is there any similar way to optimize the above function?
Best Answer