Assume and find different possible unknown variables of inequalities , Need help please
2 次查看(过去 30 天)
显示 更早的评论
Hi All,
I have inequalities, with two unkonwn variables, So How could I assume one variables with different numbers, and get the others?
I mean:
-15<10*x+2*y<20
How could I assume for example x=2, 3, and so on, and then find answer of (y) depends on the value of (x)
I have been trying to apply assume, and find commands, but unfortunaley, I could not So I hope anyone could help me
Please
Looking to hearing from you
Thank you,
0 个评论
回答(1 个)
John D'Errico
2019-8-23
First, you cannot write a pair of inequalities that way in MATLAB. It works as a conventional form, because people know what you intended. But MATLAB will misinterpret things.
Next, computers don't deal well with strict inequalities, because of floating point problems.
You have
-15 < 10*x+2*y
AND
10*x+2*y < 20
If we solve for y that just meets the requirements in those two cases, we would see this:
syms x y
solve(-15 == 10*x+2*y,y)
ans =
- 5*x - 13/2
solve(10*x+2*y == 20,y)
ans =
9 - 5*x
We can think f it as an interval for y, as a function of x.
yinterval = [ solve(-15 == 10*x+2*y,y),solve(10*x+2*y == 20,y)]
yinterval =
[ - 5*x - 15/2, 10 - 5*x]
yinterval = matlabFunction(yinterval)
yinterval =
function_handle with value:
@(x)[x.*-5.0-1.5e+1./2.0,x.*-5.0+1.0e+1]
So now for any specific x, we can produce an interval for y that satisfies the inequalities.
yinterval(2)
ans =
-17.5 0
yinterval(3)
ans =
-22.5 -5
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!