ne
Define inequality
Description
Examples
Set and Use Assumption Using Not Equal
Use assume
and the relational operator
~=
to set the assumption that x
does not equal to
5:
syms x assume(x ~= 5)
Solve this equation. The solver takes into account the assumption on variable
x
, and therefore returns only one solution.
solve((x - 5)*(x - 6) == 0, x)
ans = 6
Input Arguments
Tips
Calling
~=
orne
for non-symbolicA
andB
invokes the MATLAB®ne
function. This function returns a logical array with elements set to logical1 (true)
whereA
is not equal toB
; otherwise, it returns logical0 (false)
.If both
A
andB
are arrays, then these arrays must have the same dimensions.A ~= B
returns an array of inequalitiesA(i,j,...) ~= B(i,j,...)
If one input is scalar and the other an array, then the scalar input is expanded into an array of the same dimensions as the other array. In other words, if
A
is a variable (for example,x
), andB
is an m-by-n matrix, thenA
is expanded into m-by-n matrix of elements, each set tox
.
Alternatives
You can also define inequality using eq
(or its shortcut ==
) and the logical negation not
(or ~
). Thus, A ~= B
is equivalent to
~(A == B)
.