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

1 次查看(过去 30 天)
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 ????

回答(1 个)

Star Strider
Star Strider 2021-4-15
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.)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by