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

1 visualización (últimos 30 días)
Tim Kim
Tim Kim el 15 de Abr. de 2021
Comentada: Star Strider el 22 de Abr. de 2021
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 ????

Respuestas (1)

Star Strider
Star Strider el 15 de Abr. de 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)
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 comentarios
Tim Kim
Tim Kim el 21 de Abr. de 2021
Hey thanks for that. I didn't even think of solving for dRound. I appreciate it heaps.

Iniciar sesión para comentar.

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by