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

조회 수: 9 (최근 30일)
Bob photonics
Bob photonics 2018년 5월 25일
댓글: Bob photonics 2018년 6월 15일
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
Bob photonics
Bob photonics 2018년 5월 30일
Still waiting for an answer to the first part, the first piece of code.

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 5월 27일
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
Walter Roberson
Walter Roberson 2018년 6월 15일
Sorry, I do not know. I recommend opening a support case.
Bob photonics
Bob photonics 2018년 6월 15일
Thank you very much for all the help and I'll do that. The help is definitely appreciated ;)

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

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by