Assume and find different possible unknown variables of inequalities , Need help please

1 回表示 (過去 30 日間)
Ali Tawfik
Ali Tawfik 2019 年 8 月 23 日
コメント済み: Ali Tawfik 2019 年 8 月 24 日
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,

回答 (1 件)

John D'Errico
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
  6 件のコメント
Ali Tawfik
Ali Tawfik 2019 年 8 月 24 日
Hi Again,
Would you mind having a look for the final code after your suggestions,
clc;
syms x y real;
neg=solve(-15 == 10*x+2*y,y)
pos=solve(10*x+2*y == 20,y)
yinterval = [ neg,pos]
%% Add function
function myfunc(x)
neg=input('enter equation ') % I have written yinternal(1) %% (got error of undefined variable )
pos=input('enter equation ') %% (got error of undefined variable )
yin(:,1)=[cc,mm]
end
ANy help!
Ali Tawfik
Ali Tawfik 2019 年 8 月 24 日
Hi John,
I do not know, why you remove the question , as you do not have time to answer?
So I wish you could have time, to answer my question, or allow me to post the question, and allow others to see!
Thanks,

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by