vpasolve and solve return empty sym 0-by-1, SOLUTION DOES EXIST
Show older comments
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
Bob photonics
on 30 May 2018
Answers (1)
Walter Roberson
on 27 May 2018
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
Bob photonics
on 27 May 2018
Walter Roberson
on 30 May 2018
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.
Bob photonics
on 31 May 2018
Walter Roberson
on 31 May 2018
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.
Walter Roberson
on 12 Jun 2018
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
Jesus Mezquita
on 14 Jun 2018
Using the additional equations but same results. Values outside the limits.
Bob photonics
on 14 Jun 2018
Edited: Bob photonics
on 14 Jun 2018
Walter Roberson
on 15 Jun 2018
Sorry, I do not know. I recommend opening a support case.
Bob photonics
on 15 Jun 2018
Categories
Find more on Equation Solving 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!