vpasolve does not handle inequalities correctly

7 views (last 30 days)
Jesse
Jesse on 29 Jun 2015
Answered: Jesse on 7 Jul 2015
Hello MATLAB community,
I am currently experiencing a problem with vpasolve's handling of inequalities, mainly them not working. I am running the following on Windows 7:
MATLAB R2015a
v8.5.0.197613
Windows 64-bit
consider the following simple quadratic example
x^2-12.5*x+37==0
this has two solutions: x = 4.8138593383654928350373471329453 or x = 7.6861406616345071649626528670547
if we run vpasolve without an interval we get the two solutions: syms x
xx=vpasolve(x^2-12.5*x+37==0,x);
xx =
4.8138593383654928350373471329453
7.6861406616345071649626528670547
now, let's say we want to find the first solution, we know that it is lest than 5 so we bound our search between 0 and 5:
syms x
xx=vpasolve(x^2-12.5*x+37==0,x,[0,5]);
this gives us the solution
xx =
4.8138593383654928350373471329453
which is great but let's say we don't know the solution, just that it's less than five; we would use the inequality option:
syms x
xx=vpasolve([x^2-12.5*x+37==0,x<5],x);
but this returns
xx =
Empty sym: 0-by-1
which of course is not true. My particular problem is a more sophisticated multivariate problem but this example shows all the problems that I currently face. Any help would be greatly appreciated.
Cheers,
Jesse V

Answers (2)

Jesse
Jesse on 7 Jul 2015
I have worked out the solution to this problem, and hopefully it will help others.
First consider an (arbitrary) inequality
x - y < 5
we can rearrange this to be an inequality with some algebraic tricks, consider this rearranged to
x - y - 5 < 0
then if the inequality holds true the left hand side must be negative, this can be made an inequality by use of the sign function:
sign(x-y-5)==-1
now, MATLAB does not allow more constraints than parameters, so we just add a fake parameter!
For example, the solution to the previous code would be:
syms x dummy
[xx,~]=vpasolve([x^2-12.5*x+37==0,sign(x-5)==-1],[x,dummy])
where the tilde suppresses the output of the unneeded dummy variable. Now if the answer is less than five the equality is held.
Cheers,
Jesse

Mischa Kim
Mischa Kim on 29 Jun 2015
Jesse, according to the documentation
" vpasolve ignores assumptions set on variables. You can restrict the returned results to particular ranges by specifying appropriate search ranges using the argument init_guess."
In other words, you could use
syms x
xsol = vpasolve(x^2 - 12.5*x + 37 == 0, x, [-inf,5]);
if you don't know the solution, just that it's less than five
  1 Comment
Jesse
Jesse on 29 Jun 2015
Edited: Jesse on 29 Jun 2015
Sorry, I guess my example was too simplistic then, the actual constraint is on a function of the variable and the variable example exhibited the same error. Consider instead something like cosh(x)*cos(y)<1, which is very similar to my true problem, when giving an equality like that it also returns a null result despite there really being a well defined answer in that region.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!