# Returning to a function and changing variables if ans is false?

16 views (last 30 days)
Tim Kim on 15 Apr 2021 at 1:10
Commented: Star Strider on 22 Apr 2021 at 0:52
If someone can link me to a similar answer, I am sorry I could not find it.
I am calculating required beam depths to hold a certain load and I have an equation that tests a certain depth, and it must be less than the max strain allowed.
If my calculated value (Fs) is greater than what is allowed (Fs_max), how do I loop back to the equation and add a factor of 10 or so to the intital variable (dRound) so that it can run tests until it is <= max allowed?
Thanks.
if dRound > d
Fs_max = input('Enter max shearing force (Fs max) in MPa ');
V_max = W/2;
Fs = (3/2)*((V_max*10^3)/(b*dRound));
fprintf('Shearing force is = %f MPa\n', Fs);
end
end
if Fs > Fs_max
return ????

Star Strider on 15 Apr 2021 at 1:25
I would do something like this, and treat it as an optimization (specifically root-finding) problem, returning the value of ‘dRound’ such that ‘Fs’ approximately equals ‘F_Max’:
Fs = @(dRound,W,b,F_max) (3/2)*((W/2*1E3)/(b*dRound)) - F_max;
dRound0 = 10;
F_max = 1000; % I Have No Idea What This Values Should Be
W = pi; % I Have No Idea What This Values Should Be
b = 42; % I Have No Idea What This Values Should Be
[dRound_est, Fs_val] = fsolve(@(dRound)Fs(dRound,W,b,F_max), dRound0)
The fzero function might also work here, however when I tried it with these values, it returned NaN. (It would be a direct substitution for fsolve in this code.)
##### 2 CommentsShowHide 1 older comment
Star Strider on 22 Apr 2021 at 0:52
My pleasure!