vpasolve did not work with some special values of variables

5 views (last 30 days)
Does anyone please help me to clarify what the problem might be. I use vpasolve to solve Manning's equation. This is the code:
%%Variable
c1=1.486; Q=50; b=20; m=2; n=0.02; S=0.01; g=32.2;
syms yo
Sol_yo = vpasolve((c1/n)*(b+m*yo)*yo*(S^0.5) *(((b+m*yo)*yo)^(2/3)) - ((b+2*yo*sqrt(1+m*m))^(2/3)*Q)==0,yo);
disp('Normal depth: '); vpa(Sol_yo)
Problem is: with m = 2 or some other values around 2. The function gave me a complex number, which is not correct. With other value of m, the function work well.
If I use while loop:
yo=3;
Sol_yo = (c1/n)*(b+m*yo)*yo*(S^0.5) *(((b+m*yo)*yo)^(2/3)) - ((b+2*yo*sqrt(1+m*m))^(2/3)*Q);
while Sol_yo > 0.000001
yo=yo-0.001
Sol_yo = (c1/n)*(b+m*yo)*yo*(S^0.5) *(((b+m*yo)*yo)^(2/3)) - ((b+2*yo*sqrt(1+m*m))^(2/3)*Q);
end
then everything is just fine.
My question is: how can I get vpasolve worked with any values of variable m? and why it did not work in the first place?
Thank you very much for your time and help!
Best,
Duc.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Feb 2016
vpasolve() is defined to find any one solution that satisfies all the criteria it has been told about. vpasolve() will not be restricted to real-valued solutions unless you have added constraints to the variables in order to disallow such solutions.
  4 Comments
Walter Roberson
Walter Roberson on 28 Feb 2016
You can specify a search range of [realmin, inf] for vpasolve()
Checking the formula further, for positive m, y0 will be in the range 0 to .5310799190444193; larger y0 require negative m.
Also, for negative m, there will be two positive roots.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!