Solving Inequalitis in Matlab

Hello everyone.
I apologize for the question which maybe looks stupid but I have problems in solving inequalities with Matlab.
For instance, how can I solve this:
x^2 > 5 ?
If I write:
syms x
solve(x^2 > 5, x)
is not correct:(
Moreover, if I have more parameters and I have to specify the conditions of them, e.g a>0, b>0, n<1 with the inequality given by: 2*a^n +5b^2 -4*a + 2*b > 9,
how can I solve it, for instance, with respect to a?
I tried
syms a b n
solve(2*a^n +5b^2 -4*a + 2*b > 9, a>0, b>0, n<1, a)
but didn't work
:(
Thank you for any kind help

 Risposta accettata

Matt Tearle
Matt Tearle il 18 Feb 2014
I'm not sure what you mean that the solution to x^2 > 5 "is not correct". When I do
syms x
solve(x^2 > 5,x)
I get that x is in the intervals (sqrt(5),Inf) or (-Inf,-sqrt(5)), which looks correct to me. If you want to add restrictions, such as x > 0, you can use assume:
assume(x > 0)
solve(x^2 > 5,x)
Now it just says (sqrt(5),Inf).
The problem with your more complicated example is that it's just too complicated! If you plug in specific values for n and b it works fine. It can even handle
assume(a > 0)
assume(b > 0)
solve(2*a^2 + 5*b^2 - 4*a + 2*b > 9, a)
But it thought long and hard about
solve(2*a^(1/3) + 5*b^2 - 4*a + 2*b > 9, a)
before saying that it couldn't find an explicit solution. Math is hard, sorry.

3 Commenti

Kodi
Kodi il 18 Feb 2014
Modificato: Walter Roberson il 22 Dic 2016
Hi Matt, thank you for your reply:)
I don't know what to say, it gives me error when I try to solve this:
syms x
solve(x^2 > 5,x)
It says:
??? Error using ==> sym.sym>notimplemented at 2653
Function 'gt' is not implemented for MuPAD symbolic objects.
Error in ==> sym.sym>sym.gt at 801
notimplemented('gt');
..I don't know why!!
:/
Oh, weird. What version are you running?
Sufficiently old versions of MATLAB did not support using relationship operators for symbolic values. You had to instead use expressions such as
syms x
syms delta_x positive
solve(x^2 - 5 - delta_x, x)
under the logic:
x^2 > 5 implies x^2 - 5 > 0 implies there is a positive number delta_x such that x^2 - 5 = delta_x which implies there is a positive number delta_x such that x^2 - 5 - delta_x = 0

Accedi per commentare.

Più risposte (3)

3 voti

use this,
syms x
s=solve(x^2 < 5,x,'ReturnConditions', true);
s.conditions
bobo zhu
bobo zhu il 22 Dic 2016
Modificato: Walter Roberson il 22 Dic 2016
syms x
a=solve(x-2 > 5,x)
a =
8
>> syms x
a=solve(x-2 <= 5,x)
a =
6
why? i don't no;somebady know the reason

7 Commenti

It appears to be a bug to me. It should return intervals.
It works in R2014a; I am working on installing later versions to figure out exactly when the problem started.
You can see the problem more obviously with
syms x
solve(x>7)
which in the last couple of releases has replied with 8 instead of with an interval.
The problem appears to start with R2014b.
I will create a bug report.
Mathworks Support points me to using ReturnConditions
sol = solve(x>7, 'ReturnConditions', true)
Joshua Long
Joshua Long il 23 Dic 2016
Modificato: Joshua Long il 23 Dic 2016
Just to add to what Walter, said this behavior changed in R2014b.
"solve" will return an expression that satisfies the equations passed in, but it may not include all of the solutions. You can check out the "ReturnConditions" name-value pair doc for some examples on how to use the "conditions" returned:
Previously "solve" would return a "Dom::Interval" MuPAD object that cannot be used for further computation in MATLAB.
solve(x>7, x < 10)
gives
15/2
so we can see that the rule is not "integers".
Experimentally the rule appears to be
break the solutions up into disjoint intervals
for each of the disjoint intervals expressible through a simple pair of bounds,
if both bounds of the interval are the same then
if that bound is infinite
emit empty rather than the infinite bound
else
emit that bound
end
elseif the bounds are -inf and +inf
emit 0
elseif one of the bounds is infinite
emit the other bound plus 1 * sign() of the infinity
elseif 0 is in the interval
emit 0
elseif pi is in the interval
emit pi
else
emit the average of the bounds
end
end
return the union of all of the emitted values
When there are intervals that are not disjoint, the outputs are similar to the above, but instead of the plain average of two bounds, the min() and max() of the bounds that enclose the interval (whether open or closed) are calculated and those are averaged.
exp(1) is also a possible solution when pi is not in the interval.

Accedi per commentare.

John BG
John BG il 23 Dic 2016
Modificato: John BG il 25 Dic 2016
perhaps you'd consider upgrading to R2016
eq=x>5^.5
eq =
5^(1/2) < x
solve(eq,x)
=
5^(1/2) + 1
or
syms x
solve(x^2 > 5,x)
=
5^(1/2) + 1
- 5^(1/2) - 1
it's even odder
assume(x,'clear')
a=solve(x-2 < 5,x)
a =
6
assume(x,'real')
>> a=solve(x-2 < 5,x)
a =
6
assume(x,'rational')
a=solve(x-2 < 5,x)
a =
0
or
assume(x,'positive')
>> a=solve(x-2 < 5,x)
a =
1
to avoid getting into how many decimal digits the answer should be, set by digits? by the type of the input variables? it seems as function solve simplifies the answer to integer type.
Regarding why when assume set to 'positive' and 'rational' then the answer goes to 0 or 1, don't know.
and for the record, there are no stupid questions, just bad teachers

5 Commenti

"and for the record, there are no stupid questions, just bad teachers"
A couple of months ago, someone asked me to write their university project for them. They stated the project title, but gave no indication that they had done any work at all on the topic. I politely declined, indicating that they should post their attempt and ask specific questions. The response I got back was, as they say, "Not printable in a family newspaper".
I wonder who was the "bad teacher" in that exchange:
  • myself for not doing multiple hours of research and writing and testing in order to provide the person with the code that they could then hand in as their own, for their academic credit, without their having done anything more strenuous than having located me and passing the project title on to me? Is it the proper role of the teacher to do all of the work for anyone who asks?
  • their professor / teacher / teaching assistant, for failing to make clear that academic cheating is inexcusable even if the perpetrator is not caught ?
  • their society, which has developed a meritocracy where what is rewarded is not actual skills in a topic but rather skill in cheating and manipulating people ?
  • their parents, for not properly teaching them individual responsibility?
Consider for example,
"Cheating in school exams has been going on in Bihar for as long as one can remember. A mafia, comprising teachers and school authorities, connives with parents of students who bribe them to rig entire answer sheets.
Sometimes teachers will complete exam papers for their students, while the students sit at home. Another example: a colleague, who studied in Bihar, told me that when she went to school more than a decade ago, teachers would often write answers on the blackboard during exams."
Am I a "poor teacher" for refusing to go along with those kinds of activities?
John BG
John BG il 25 Dic 2016
Modificato: John BG il 25 Dic 2016
IA you are a really smart contributor to this forum, top credit, best in your business at least from your contributions, while reading your comments posted 19 hours ago:
. A couple of months ago, someone asked me to write their university project for them. They stated the project title, but gave no indication that they had done any work at all on the topic .
like half the questions in this forum
. "Not printable in a family newspaper". .
?!? I do not really understand the answer you got but it seems as the typical decoying by pretending that you were the one who submitted something to them for printing when in fact you were the one approached by them to think and write for them. Urban cammo.
It happens all the time, everywhere, the BBC recently published an undercover recollection of people in London UK, no need to go to Asia, who forge and write assignments for others on regular basis for a living, and they don't drive Yugos.
myself for not doing multiple hours of research and writing and testing in order to provide the person with the code that they could then hand in as their own, for their academic credit, ..
there are legal ways to write assignments for others, but academically speaking it is like pretending to speak Russian when you don't, they will be caught at every corner, because once they get their degree, unless they go to a place of all deaf people you are going to catch their lack of Russian skills in 5 seconds, won't you?
their professor / teacher / teaching assistant, for failing to make clear that academic cheating is inexcusable even if the perpetrator is not caught ?
who cares? why are you wondering whether their teachers .. is the cause?
their society, which has developed a meritocracy where what is rewarded is not actual skills in a topic but rather skill in cheating and manipulating people ?
You are going really deep here, as if you could remotely fix any of those points.
their parents, for not properly teaching them individual responsibility?
???
try this
repmat('I dont care',1,Inf)
At this point I politely request your outstanding attention back on MATLAB and SIMULINK.
It's a wild world, people lie, get on with it, the chessboard has black squares too.
by the way with all your writing how is it you didn't mention reporting to police?
.
by the way .
.
IA, if you find my comments useful, would you please vote my lines? thanks in advance
Merry Christmas
John BG
"Not printable in a family newspaper" means that they swore at me for having turned them down, using language that is not suitable for polite company or a professional forum.
"who cares? why are you wondering whether their teachers .. is the cause?"
You posted "there are no stupid questions, just bad teachers" so I am asking you to tell us who the bad teacher is when students demand that we write their assignments for them. Under your claim it is not the question that is bad but rather the teacher that is bad, so which teacher is the problem one?
It is a fundamental question here, because if the response is provably that we volunteers are the "bad teachers" when we refuse to do assignments on demand, then the likely response is that a number of us volunteers would quit.
John BG
John BG il 25 Dic 2016
Modificato: John BG il 25 Dic 2016
ok,
the term 'bad teachers' has been used, and I will keep using it, in general terms, and no allusion has been made to any contributor in this forum, or at any time to a particular.
My experience and that from many other I know and heard about is that there is an increasing 'soft' corruption in universities regarding the attitude of 'pretending teaching' while 'preventing learning' by
  • minimising the useful taught contents
  • minimising tutorials
  • using a host of carefully 'cul-de-sac' pointers skillfully deployed to exhaust the time the best student would allocate to learn something.
  • expanding a few syllabus points while squashing, shrinking, or even mistaking or completely missing many key syllabus contents that is really critical for students to complete.
  • discriminating students on grounds of ethnicity, genre and other non-study related factors, it comes in either the abuse of the so called positive discrimination, or the endemic selection practice seen in many places.
  • not requesting a certain volume of course work, letting weeks go by without asking for a single submission, but students having to fill out the HEARS profile, that if you are not aware of it, it's a UK initiative to have students making available their coursework as CV support material, when looking for employment. It's a good thing, but when the requested coursework is a joke or even non-existent, such bad teachers are purposely rendering the chances of many null while they nurture and focus on a few to have all the trumps.
  • It's a fact that Universities receive huge amounts of moneys to do research, from either governments and companies, to teach, transfer know-how, and the companies to promote their tools.
  • Yet it's a fact that perhaps there are less jobs than students, many teachers choose in advance the candidates they will recommend to employers and even allow to complete license training while blocking a majority of hard working students who are willing and can achieve the know-how yet they will be fouled to waste time and resources that employers will not consider worth employing.
And we all keep hearing news about the UK in need for engineers, and the UK having to import foreign skilled workers but I think, me and many, the immigration corruption is especially pernicious at endemically pulling foreign talent for the sake of diverting funds away from local student.
In all this MATHWORKS offers an opportunity for the correct learning of Mathematics. MATLAB levels up the playground in the sense that a bad teacher can no longer argue that MATLAB is not required to learn Maths, that University students have to first spend years solving problems on paper, isolated, away from the internet, while those bad teachers and the few chosen ones, chosen with trumped marks, exams release to a few in advance or even fake accreditation.
There are universities that have recently changed attitude towards products like MATLAB and SIMULINK, but just to cover their wrong doing for years of, on one side receiving MATHWORKS full training and licences for students, yet blocking, preventing access to such tools to the majority of students arguing the most bizarre excuses.
So now that clear line has been defined on this point, back on track? just focus on the MATLAB SIMULINK questions, whether you answer them or you don't, but there is no way to stop next student with doubts in coursework to show up in this forum and ask for solutions:
what-if that student has a resentful teacher preventing learning?
what-if then such student goes to MAPLE or any other product and finds a solution there?
The ethic and moral grounds that you argue at each question that may be coursework either refrains many from answering it, to give it try, and the same student may feel asking in this forum is not worth the effort.
The message 'do not bring your coursework here' is in my opinion pointless. Even more, it is kind-off shooting your own foot, and the feet of all other volunteers helping in this forum, I am also a volunteer here, don't work for Mathworks.
So why not considering at least in these special days, just answer the question or let others answer the question.
There is no need for moral and ethical reminders, we don't have to tell not to bring coursework, assignments. This forum may try to curve piggybackers, lazy students, copy machines, yet it diverts effort from what has to be kept in the centre: MATLAB and SIMULINK.
The Universities where such students study are legally bound to check whether their coursework is genuine. An smart employer should check the intelligence of candidates along with the level of deviancy, for the sake of not wasting their money.
Obviously, common sense, Renne's: if one reads a question like for instance 'how to use MATLAB to calculate how many grams of plastic explosive to bring down a bridge' or 'how to calculate the lethal dose of Zyklon as function of body weight' I don't know others but I would immediately report it.
But besides reporting, what else can be done by volunteers here? the rules of the forum are clear, stick to them, be polite, no need to patronise people answering MATLAB forum questions by rising questions with moral and ethical directives.
Jan
Jan il 25 Gen 2017
@John BG: The statement "do not bring your coursework here" has not been issued by Walter or any other member of this forum. We do not like homework questions, when the OPs do not show any own effort. Posting a full solution in such cases does not support the OP in learning and decrease the forum's quality and reputation. Because I want to encourage my students to use this forum, I do not want their homework to be solved here.
I reply exactly as if the OPs are students and ask me personally: "Please solve my homework" gets a "no", while I spend time for solutions, when a specific question is asked.
If it is the standard in forum to solve do-it-for-me question, the sophisticated and experienced Matlab cracks would leave the forum soon.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by