Asked by Bob photonics
on 25 May 2018 at 13:18

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

Answer by Walter Roberson
on 27 May 2018 at 0:40

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

Bob photonics
on 14 Jun 2018 at 14:29

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]

Walter Roberson
on 15 Jun 2018 at 4:19

Sorry, I do not know. I recommend opening a support case.

Bob photonics
on 15 Jun 2018 at 14:32

Thank you very much for all the help and I'll do that. The help is definitely appreciated ;)

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Bob photonics (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/402557-vpasolve-and-solve-return-empty-sym-0-by-1-solution-does-exist#comment_573531

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

Sign in to comment.