This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

~=, _approx

Approximate equality

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
_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 specified 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 side and the right side. Use lhs and rhs to extract these operands.

    Note:   a ~= b is not equivalent to a - b ~= 0.


Example 1

In the following example, 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(%)

For equations with floating-point numbers, use the operator ~= instead of =. The functions bool and is test whether the floating-point approximations coincide up to the relative precision given by DIGITS:

1.5 ~= 3/2; 
bool(1.5 ~= 3/2);
is(1.5 ~= 3/2);


x, y

Arbitrary MuPAD® objects

Return Values

Expression of type "_approx".

See Also

MuPAD Functions

Was this topic helpful?