Inequalities "less than or equal to" and "greater than or equal to"
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
x <= y
x >= y
_leequal(x
,y
)
x <= y
and x >= y
define
inequalities.
x <= y
represents the Boolean statement
"x
is less than or equal to y
".
It is equivalent to the function call _leequal(x,y)
.
x >= y
represents the Boolean statement
"x
is greater than or equal to y
".
It is always converted to y <= x
, which is equivalent
to the function call _leequal(y,x)
.
These operators return symbolic Boolean expressions. If only
real numbers of Type::Real
are
involved, these expressions can be evaluated to TRUE
or FALSE
by
the function bool
.
They also serve as control conditions in if
, repeat
, and while
statements. For floatingpoint intervals, these operators
are interpreted as "strictly less than or equal to"
and "strictly greater than or equal to". See Example 2. Further, Boolean expressions
can be evaluated to TRUE
, FALSE
, or UNKNOWN
by the function is
. Tests using is
can also be applied
to constant symbolic expressions. See Example 4.
bool
also
handles inequalities involving character strings. It compares them
with respect to the lexicographical ordering.
Inequalities have two operands: the left side and the right
side. Use lhs
and rhs
to extract these
operands.
The operators <=
and >=
produce
symbolic inequalities. They can be evaluated to TRUE
or FALSE
by
the function bool
if
only real numbers of type Type::Real
(integers,
rationals, and floats) are involved:
1.5 <= 3/2; bool(%)
Comparison of intervals is interpreted as "strict", that is, all combinations of numbers in the intervals must fulfill the relation:
bool(0...1 <= 2...3), bool(0...2 <= 1...3), bool(0...1 <= 1...2)
Compare character strings:
if "text" <= "t"."e"."x"."t"."book" then "yes" else "no" end
bool("a" >= "b")
Note that bool
does not perform symbolic
simplification and therefore cannot handle some combinations of symbolic
expressions; the function is
does
perform symbolic simplification:
bool(sqrt(6) <= sqrt(2)*sqrt(3))
Error: Cannot evaluate to Boolean. [_leequal]
is(sqrt(6) <= sqrt(2)*sqrt(3))
Inequalities are valid input objects for the system function solve
:
solve(x^2  2*x >= 3, x)
The operator <=
can be overloaded by
userdefined domains:
myDom := newDomain("myDom"): myDom::print := x > extop(x):
Without overloading _leequal
, elements of
this domain cannot be compared:
x := new(myDom, PI): y := new(myDom, sqrt(10)): bool(x <= y)
Error: Cannot evaluate to Boolean. [_leequal]
Now, a slot"_less"
is
defined. It is called, when an inequality of type "_less"
is
evaluated by bool
.
The slot compares floatingpoint approximations if the arguments are
not of type Type::Real
:
myDom::_leequal := proc(x, y) begin x := extop(x, 1): y := extop(y, 1): if not testtype(x, Type::Real) then x := float(x): if not testtype(x, Type::Real) then error("cannot compare") end_if end_if: if not testtype(y, Type::Real) then y := float(y): if not testtype(y, Type::Real) then error("cannot compare") end_if end_if: bool(x <= y) end_proc:
x, y, bool(x <= y), bool(x >= y)
bool(new(myDom, I) <= new(myDom, PI))
Error: cannot compare [myDom::_leequal]
delete myDom, x, y:

Arbitrary MuPAD^{®} objects 
Expression of type "_leequal"
.
x
, y