Main Content

ne

Define inequality

Description

A ~= B creates a symbolic inequality.

example

ne(A,B) is equivalent to A ~= B.

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

collapse all

Input, specified as a number, vector, matrix, or array, or a symbolic number, scalar variable, matrix variable, array, function, matrix function, or expression.

Input, specified as a number, vector, matrix, or array, or a symbolic number, scalar variable, matrix variable, array, function, matrix function, or expression.

Tips

  • Calling ~= or ne for non-symbolic A and B invokes the MATLAB® ne function. This function returns a logical array with elements set to logical 1 (true) where A is not equal to B; otherwise, it returns logical 0 (false).

  • If both A and B are arrays, then these arrays must have the same dimensions. A ~= B returns an array of inequalities A(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), and B is an m-by-n matrix, then A is expanded into m-by-n matrix of elements, each set to x.

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).

Version History

Introduced in R2012a

expand all