"solve" bug?

2 次查看(过去 30 天)
Robert Leo
Robert Leo 2016-4-28
Hello everyone, I am writing because I have a problem with the resolution of inequality.
syms x;
f = 6*x + 24;
s = solve(f < 0, x, 'Real', true)
This is the result:
s =
-5
I have tried everything to fix it. Because the result is wrong? Correct result: x <- 4. Sorry for my bad English
  2 个评论
Star Strider
Star Strider 2016-4-28
Just using:
s = solve(f)
gives -4 as expected.
Robert Leo
Robert Leo 2016-4-28
But I want the interval

请先登录,再进行评论。

回答(2 个)

MHN
MHN 2016-4-28
编辑:MHN 2016-4-28
It gives you the first integer number that meets the criteria (f<0) which is -5 (for -4 you should write f<=0). Matlab is not a good tool for symbolic calculation and I do not think it gives you that result (x<-4, or x<=-5). Btw, of course it is not a bug in solve function !!!
  1 个评论
Robert Leo
Robert Leo 2016-4-28
编辑:Robert Leo 2016-4-28
Ok, thanks for the answer. But how do I solve my problem? What can I use? With f <= 0 the result does not change

请先登录,再进行评论。


Raghad Alharbi
Raghad Alharbi 2022-2-16
Selection = menu ('Welcome to Relations' ...
'Reflexivity' ...
'Symmetry' ...
'Transitivity' ...
'Exit the menu')
A = [0,1,2,3,4,5]; Z1 = []; Z2 = []; Z3 = [];
while Selection < 7
switch Selection
case 1 Reflexivity
i = 1;
while i < 7
n1 = input(' Enter rfist integer for n1; ');
if ismember ([n1],A) == 1
fprintf('n1 belongs to A\n')
break
else
i = i+1;
end
end
i = 1;
while i < 7
n2 = input('Enter rfist integer for n2; ');
if ismember ([n2],A) == 1
fprintf('n1 belongs to A\n')
break
else
i = i+1;
end
end
if ismember([n1],A) == 1 && ismember ([n2],A) == 1 && n1 == n2
fprintf('Yes, R Reflexivity\n')
else
fprintf('No, R is not Reflexivity\n')
end
case 2 Symmetry
n1 = input('Enter frist integer for n1: ');
n2 = input('Enter second integer for n2: ');
if ismember ([n1], A) == 1 && ismember ([n2] ,A) == 1 && n1 ~= n2
Z1 (end + 1) = n1;
Z1 (end + 1) = n2;
Z2 (end + 1) = n2;
Z2 (end + 1) = n1;
fprintf('Yes, R Symmetry\n')
else
fprintf('no, R is not Symmetry\n')
end
case 3 Transitivity
n1 = input('Enter frist integer for n1: ');
n2 = input('Enter second integer for n2: ');
n3 = input('Enter third integer for n3: ');
if ismember ([n1], A) == 1 && ismember ([n2] ,A) == 1 && ismember ([n3], A) == && n1 ~= n2 && n2 ~= n3
Z1 (end + 1) = n1;
Z1 (end + 1) = n2;
Z2 (end + 1) = n2;
Z2 (end + 1) = n3;
Z3 (end + 1) = n1;
Z3 (end + 1) = n3;
fprintf('Yes, R Transitivity\n')
else
fprintf('no, R is not Transitivity\n')
end
case 4 Exit menu
break;
end
Selection = menu('Welcome to Reflexivity, Symmetry, and Transitivity' ...
'Reflexivity' ...
'Symmetry' ...
'Transitivity' ...
'Exit the menu')
end
fprintf('You have left the menu, Have a good day!\n')

产品

Community Treasure Hunt

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

Start Hunting!

Translated by