vpasolve does not handle inequalities correctly

조회 수: 9 (최근 30일)
Jesse
Jesse 2015년 6월 29일
답변: Jesse 2015년 7월 7일
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

답변 (2개)

Jesse
Jesse 2015년 7월 7일
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 2015년 6월 29일
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
Jesse
Jesse 2015년 6월 29일
편집: Jesse 2015년 6월 29일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by