vpasolve and solve return empty sym 0-by-1, SOLUTION DOES EXIST

When I run this code I get empty strings for when setting a range for vpasolve, when I do not set the range I only get one solution, even with random on. The range is set so that it does include the one solution matlab gives me, x=2, y=0 and b=1.5. for the range I've tried -Inf Inf and NaN NaN, to have it try all numbers. So please do not give me the answer of saying that my system has no solution, it clearly does. It also won't solve it symbolicly (same issue with solve), while I can give 1 possible solution. 0.5*(x+y)=1, b*(x+y)=3 ---> x+y=2 and b=1.5
So something else must be wrong, I would appreciate it if you let me know what I'm doing wrong here.
clear all; %just to be safe
syms x y b
a=0.5;
somevalue=1;
someothervalue=3;
eq1= a*x+a*y == somevalue; %this is your first equation
eq2= b*x+b*y == someothervalue; %this is your 2nd equation
eqs=[eq1,eq2]; %use this for vpasolve and set range in range
vars=[x,y,b]; %these are the variable you want to solve for
range = [-1 3; -2 5; -Inf Inf]; %NaN means you set no range
%you can use solve or vpasolve, second one being numeric, which is the one you'll probably want
sol=zeros(5,3);
for i = 1:5
temp1 = vpasolve(eqs, vars, range, 'random', true);
temp = solve(eqs, vars);
sol(i,1) = temp.x;
sol(i,2) = temp.y;
sol(i,3) = temp.b;
end
sol
temp1.x
temp1.y
temp1.b
Now I have another clear problem/error when using the solve option, obviously the answer here should be 9:
syms x
eq12 = -3 == sqrt(x);
solve(eq12)
ans =
Empty sym: 0-by-1

1 Comment

Still waiting for an answer to the first part, the first piece of code.

Sign in to comment.

Answers (1)

sqrt(x) is short-hand for x^(1/2) . 9^(1/2) only refers to the primary square root, not to all square roots. Work-around:
>> syms A
>> solve(A==sqrt(x),x)
ans =
A^2
>> subs(ans,A,-3)
ans =
9

9 Comments

Thank you that's a nice work around for smaller problems :D
Although for more complicated situation it's still tricky.
Anyway do you have any clue why the first part is not giving me a solution? As that's even weirder.
vpasolve() uses a modified Newton-Raphson solver. The solver projects locations, tests, re-projects, and so on, until the root is found. The projection process can end up out of bounds even though the root is within bounds.
When you set finite bounds, you prevent vpasolve from using any information from outside those bounds to do the calculation, and vpasolve() will stop the search as soon as it hits the bounds.
That said: I find that if you set the bounds for the first variable even to -inf +inf then it will not find a solution, but it will find a solution if you set the bounds for the first variable to nan nan.
I am having difficulty coming up with a plausible reason for that; the only thing that is coming to mind is that if somehow it was wanting to project x as complex-valued then -inf +inf would rule that out. However, there is no reason why it might project such a value for x.
Thank you very much for the explanation, that already makes me understand this a bit better. I thought we could usually use the range to define the boundaries, to set a boundary condition but unfortunately that's not always true then.
One thing that I just thought of is that when you use numeric bounds, then vpasolve() assumes that the endpoints are of opposite signs, which is not the same thing as setting boundary conditions (because "boundary conditions" does not imply the edges are opposite sign.)
I do not understand exactly what is happening with that first boundary though.
Instead of setting limits through this mechanism, it might perhaps work to instead add additional equations which express inequalities, such as x >= -1 & x <= 3 & y >= -2 & y <= 5
Using the additional equations but same results. Values outside the limits.
I just tried this, and it gives me an error that it cannot find an explicit solution.
clear all; %just to be safe
syms x y b
a=0.5;
somevalue=1;
someothervalue=3;
eq1= a*x+a*y == somevalue; %this is your first equation
eq2= b*x+b*y == someothervalue; %this is your 2nd equation
%Boundary condition for x and y
cd1= x >= -1;
cd2= x <= 3;
cd3= y >= -2;
cd4= y <= 5;
eqconds=[eq1,eq2,cd1,cd2,cd3,cd4];
vars=[x,y,b]; %these are the variable you want to solve for
temp = solve(eqconds, vars);
Warning: Cannot find explicit solution.
> In solve (line 316)
Of course for vpasolve we get
temp = vpasolve(eqconds, vars)
temp =
x: [0x1 sym]
y: [0x1 sym]
b: [0x1 sym]
Sorry, I do not know. I recommend opening a support case.
Thank you very much for all the help and I'll do that. The help is definitely appreciated ;)

Sign in to comment.

Products

Release

R2016a

Asked:

on 25 May 2018

Commented:

on 15 Jun 2018

Community Treasure Hunt

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

Start Hunting!