Solving Inequalitis in Matlab
265 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Matt Tearle
2014 年 2 月 18 日
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 件のコメント
Walter Roberson
2017 年 1 月 25 日
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
その他の回答 (3 件)
tharushika deeghayu ranathunga
2021 年 11 月 20 日
use this,
syms x
s=solve(x^2 < 5,x,'ReturnConditions', true);
s.conditions
bobo zhu
2016 年 12 月 22 日
編集済み: Walter Roberson
2016 年 12 月 22 日
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 件のコメント
Walter Roberson
2016 年 12 月 24 日
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.
John BG
2016 年 12 月 23 日
編集済み: John BG
2016 年 12 月 25 日
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 件のコメント
John BG
2016 年 12 月 25 日
編集済み: John BG
2016 年 12 月 25 日
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
2017 年 1 月 25 日
@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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!