Solving an equation gives me three possible answers. How can I reference only one of these answers?

1 view (last 30 days)
syms v f eta;
f=0.0394
f = 0.0394
eqnvel = (9.801-3.802*v)*v*eta==(((f*200*(pi/4)*0.1^2)/6.434)+((27*(pi/4)*0.1^2)/64.34))*v^3;
[v]=solve(eqnvel,v)
v = 
I have three possible answers as a result of this solve. Is there a way for me to save the positive answer as a variable so I can use it in a different equation? V will change as eta changes and I would like to graph it from eta= 0.6 to eta=0.9. Any help with this would be greatly appreciated.

Accepted Answer

John D'Errico
John D'Errico on 22 Mar 2023
syms v f eta;
f=0.0394;
f = 0.0394;
eqnvel = (9.801-3.802*v)*v*eta==(((f*200*(pi/4)*0.1^2)/6.434)+((27*(pi/4)*0.1^2)/64.34))*v^3;
[v]=solve(eqnvel,v)
v = 
There is no positive answer, since the non-zero roots are a function of eta, and depending on the value of eta, we might see positive or negative solutions.
fplot(v(3))
It appear that for negative eta, you get two positive real solutions.
vpa(subs(v,eta,-1))
ans = 
vpa(subs(v,eta,1))
ans = 
And for positive eta, there is one positive solution.
Can you "save" it? Sure. I might do this:
vfun = matlabFunction(v(3))
vfun = function_handle with value:
@(eta)eta.*(-1.471931584291143e+2)+sqrt((eta.*(eta.*2.60401805391858e+23+9.121045850379028e+21))./1.801439850948198e+22).*3.871466555210792e+1
Now you can use that function for anything you please. Plot it, for example.
fplot(vfun,[0,5])
Evaluate it.
result = vfun(pi)
result = 2.5707

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!