Returning to a function and changing variables if ans is false?
Afficher commentaires plus anciens
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 ????
Réponses (1)
Star Strider
le 15 Avr 2021
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)
Catégories
En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!