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

9 Ansichten (letzte 30 Tage)
Bob photonics
Bob photonics am 25 Mai 2018
Kommentiert: Bob photonics am 15 Jun. 2018
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
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
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;
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);
ans =
Empty sym: 0-by-1

Antworten (1)

Walter Roberson
Walter Roberson am 27 Mai 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 =
>> subs(ans,A,-3)
ans =
  9 Kommentare
Walter Roberson
Walter Roberson am 15 Jun. 2018
Sorry, I do not know. I recommend opening a support case.
Bob photonics
Bob photonics am 15 Jun. 2018
Thank you very much for all the help and I'll do that. The help is definitely appreciated ;)

Melden Sie sich an, um zu kommentieren.




Community Treasure Hunt

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

Start Hunting!

Translated by