I have a function and I would like for it to print out an answer if I feed it a value.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Peter Phung
le 4 Mai 2018
Réponse apportée : Star Strider
le 4 Mai 2018
I am using the Colebrook equation, which is a function of "f" and "Re" PLEASE READ(RE IS WHERE 126,400 IS). I haven't used MATLAB in a long time. Basically if I plug in a value for f into the equation, I get a value for Re. I need to do this for f = 0:0.0001:1 (which is a 10000x1 double) so I'll get the respective values for Re with respect to f = 0:0.0001:1. How do I go about doing this in MATLAB? I understand that I need to set the equation equal to zero, but I do not know what to do after that.
Here is the equation
2 commentaires
Réponse acceptée
Star Strider
le 4 Mai 2018
Probably the easiest way is to have the Symbolic Math Toolbox solve for ‘Re’, then do the calculations in an anonymous function created by matlabFunction:
syms f Re
Eqn = 1/sqrt(f) == -2*log(4.2E-5/3.7 + 2.51/(Re*sqrt(f)));
Re_sol = solve(Eqn, Re);
ReFcn = matlabFunction(Re_sol)
f = linspace(0, 1, 1E+4);
figure
semilogy(f, ReFcn(f))
grid
xlabel('f')
ylabel('Re')
This produces:
ReFcn = @(f) (1.0./sqrt(f).*(2.51e2./1.0e2))./(exp(1.0./sqrt(f).*(-1.0./2.0))-1.135135135135135e-5);
You might want to use abs(ReFcn(f) in the plot, to avoid the ‘Warning: Negative data ignored’ message.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Special Values dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!