Approximate equality
This functionality does not run in MATLAB.
x ~= y
_approx(x
,y
)
x ~= y
symbolizes approximate equality.
x ~= y
is equivalent to the function call _approx(x,
y)
.
The operator ~=
returns a symbolic expression
representing an approximate equality for numerical values x
and y
.
The calls bool(x ~= y)
and is(x ~= y)
check
whether float((x  y)/x) < 10^(DIGITS)
is
satisfied, provided x ≠ 0
and y
≠ 0
. Thus, TRUE
is returned if x
and y
coincide
within the relative numerical precision set by DIGITS
. For x
= 0
, the criterion is float(y) < 10^(DIGITS)
.
For y = 0
, the criterion is float(x)
< 10^(DIGITS)
. If either x
or y
contains
a symbolic object that cannot be converted to a real or complex floating
point number, the functions bool
and is
return the value UNKNOWN
.
Approximate equalities have two operands: the left hand side
and the right hand side. One may use lhs
and rhs
to extract these operands.
Note:

In the following, note the difference between syntactical and
numerical equality. The numbers 1.5 and
coincide
numerically. However, 1.5 is
of domain type DOM_FLOAT
, whereas
is
of domain type DOM_RAT
.
Consequently, they are not regarded as equal in the following syntactical
test:
1.5 = 3/2; bool(%)
If floatingpoint numbers are involved, one should rather use
the operator ~=
instead of =
.
The functions bool
and is
test whether the
floatingpoint approximations coincide up to the relative precision
given by DIGITS
:
1.5 ~= 3/2; bool(1.5 ~= 3/2); is(1.5 ~= 3/2);
The following expressions coincide syntactically:
_equal(1/x, diff(ln(x),x)); bool(%)
The Boolean operator not
converts
equalities and inequalities:
not a = b, not a <> b
The examples below demonstrate how =
and <>
deal
with nonmathematical objects and data structures:
if "text" = "t"."e"."x"."t" then "yes" else "no" end
bool(table(a = PI) <> table(a = sqrt(2)))
We demonstrate the difference between the syntactical test via bool
and the semantical
test via testeq
:
bool(1 = x/(x + y) + y/(x + y)), testeq(1 = x/(x + y) + y/(x + y))
Equations and inequalities are typical input objects for system
functions such as solve
:
solve(x^2  2*x = 1, x)
solve(x^2  2*x <> 1, x)

Arbitrary MuPAD^{®} objects 
Expression of type "_approx"
.