Solving for vector using syms
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to solve an equation for the variable f. I am able to make this work when I assume a constant value for Re, but would like Re to change as my vector x changes. However, when I make Re a vector, vpasolve does not work to solve for f anymore. I am not sure how to get a vector of f values using syms and vpasolve.
x = linspace(0,150,50);
vel = x./((pi/4)*(1.5)^2);
Re = 50000;
syms f
eqn = 1/sqrt(f) == -2*log10((0.0001/3.7)+(2.51./(Re*sqrt(f))));
S = vpasolve(eqn,f)
% works!
x = linspace(0,150,50);
vel = x./((pi/4)*(1.5)^2);
Re = (vel*(1.5))/(10.4*10^(-6));;
syms f
eqn = 1/sqrt(f) == -2*log10((0.0001/3.7)+(2.51./(Re*sqrt(f))));
S = vpasolve(eqn,f)
% does not work :(
0 commentaires
Réponses (1)
Walter Roberson
le 28 Nov 2019
S = arrayfun(@vpasolve,eqn,'uniform',0);
You will find that the first result is empty. It corresponds to x = 0, which gives vel = 0 which gives Re = 0, and your eqn divides by Re so you get an inf at that point. If you remove the exact 0 in x, then you can remove the 'uniform', 0 in arrayfun.
The reason your call is failing is that when you call solve() or vpasolve() with a vector or array of equations, then MATLAB tries to find values of the variables that solve all of the equations simultaneously. However, there is no single f that can satisfy all of those equations at the same time. What you really want to do is solve them independently, which arrayfun() is handy for.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!