"solve" bug?

2 visualizzazioni (ultimi 30 giorni)
Robert Leo
Robert Leo il 28 Apr 2016
Risposto: Raghad Alharbi il 16 Feb 2022
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 Commenti
Star Strider
Star Strider il 28 Apr 2016
Just using:
s = solve(f)
gives -4 as expected.
Robert Leo
Robert Leo il 28 Apr 2016
But I want the interval

Accedi per commentare.

Risposte (2)

MHN
MHN il 28 Apr 2016
Modificato: MHN il 28 Apr 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 Commento
Robert Leo
Robert Leo il 28 Apr 2016
Modificato: Robert Leo il 28 Apr 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

Accedi per commentare.


Raghad Alharbi
Raghad Alharbi il 16 Feb 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')

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by