Main Content

Test whether all equations and inequalities represented as elements of symbolic array are valid

Create vector `V`

that contains the symbolic
equation and inequalities as its elements:

syms x V = [x ~= x + 1, abs(x) >= 0, x == x];

Use `all`

to test whether all of them are valid for all values of
`x`

:

all(V)

ans = logical 1

Create this matrix of symbolic equations and inequalities:

syms x M = [x == x, x == abs(x); abs(x) >= 0, x ~= 2*x]

M = [ x == x, x == abs(x)] [ 0 <= abs(x), x ~= 2*x]

Use `all`

to test equations and inequalities of this matrix. By
default, `all`

tests whether all elements of each column are valid for all
possible values of variables. If all equations and inequalities in the column are valid
(return logical `1`

), then `all`

returns logical
`1`

for that column. Otherwise, it returns logical `0`

for the column. Thus, it returns `1`

for the first column and
`0`

for the second column:

all(M)

ans = 1×2 logical array 1 0

Create this matrix of symbolic equations and inequalities:

syms x M = [x == x, x == abs(x); abs(x) >= 0, x ~= 2*x]

M = [ x == x, x == abs(x)] [ 0 <= abs(x), x ~= 2*x]

For matrices and multidimensional arrays, `all`

can test all elements
along the specified dimension. To specify the dimension, use the second argument of
`all`

. For example, to test all elements of each column of a matrix, use
the value 1 as the second argument:

all(M, 1)

ans = 1×2 logical array 1 0

To test all elements of each row, use the value 2 as the second argument:

all(M, 2)

ans = 2×1 logical array 0 1

Test whether all elements of this vector return logical
`1`

s. Note that `all`

also converts all numeric values
outside equations and inequalities to logical `1`

s and
`0`

s. The numeric value 0 becomes logical `0`

:

syms x all([0, x == x])

ans = logical 0

All nonzero numeric values, including negative and complex values, become logical
`1`

s:

all([1, 2, -3, 4 + i, x == x])

ans = logical 1

If

`A`

is an empty symbolic array,`all(A)`

returns logical`1`

.If some elements of

`A`

are just numeric values (not equations or inequalities),`all`

converts these values as follows. All numeric values except 0 become logical`1`

. The value 0 becomes logical`0`

.If

`A`

is a vector and all its elements return logical`1`

,`all(A)`

returns logical`1`

. If one or more elements are zero,`all(A)`

returns logical`0`

.If

`A`

is a multidimensional array,`all(A)`

treats the values along the first dimension that is not equal to 1 (nonsingleton dimension) as vectors, returning logical`1`

or`0`

for each vector.