"solve" bug?

2 vues (au cours des 30 derniers jours)
Robert Leo
Robert Leo le 28 Avr 2016
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 commentaires
Star Strider
Star Strider le 28 Avr 2016
Just using:
s = solve(f)
gives -4 as expected.
Robert Leo
Robert Leo le 28 Avr 2016
But I want the interval

Connectez-vous pour commenter.

Réponses (2)

MHN
MHN le 28 Avr 2016
Modifié(e) : MHN le 28 Avr 2016
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 commentaire
Robert Leo
Robert Leo le 28 Avr 2016
Modifié(e) : Robert Leo le 28 Avr 2016
Ok, thanks for the answer. But how do I solve my problem? What can I use? With f <= 0 the result does not change

Connectez-vous pour commenter.


Raghad Alharbi
Raghad Alharbi le 16 Fév 2022
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')

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by