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
~=ornefor non-symbolicAandBinvokes the MATLAB®nefunction. This function returns a logical array with elements set to logical1 (true)whereAis not equal toB; otherwise, it returns logical0 (false).If both
AandBare arrays, then these arrays must have the same dimensions.A ~= Breturns 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
Ais a variable (for example,x), andBis an m-by-n matrix, thenAis 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).