Logical XOR for symbolic expressions
Combine two symbolic inequalities into a logical expression using
xor.
syms x range = xor(x > -10, x < 10);
Replace variable x with 11 and 0. If you replace x
with 11, then inequality x > -10 is valid and x <
10 is invalid. If you replace x with 0, both inequalities are
valid. Note that subs only substitutes the numeric values into
the inequalities. It does not evaluate the inequalities to logical 1 or
0.
x1 = subs(range,x,11) x2 = subs(range,x,0)
x1 = -10 < 11 xor 11 < 10 x2 = -10 < 0 xor 0 < 10
To evaluate these inequalities to logical 1 or 0,
use isAlways. If only one inequality is valid,
the expression with xor evaluates to logical 1. If
both inequalities are valid, the expression with xor evaluates to logical
0.
isAlways(x1) isAlways(x2)
ans =
logical
1
ans =
logical
0Note that simplify does not simplify these logical
expressions to logical 1 or 0. Instead, simplify
returns symbolic constants symtrue or
symfalse.
s1 = simplify(x1) s2 = simplify(x2)
s1 = symtrue s2 = symfalse
Convert symbolic symtrue or symfalse to logical
values using logical.
logical(s1) logical(s2)
ans =
logical
1
ans =
logical
0If you call simplify for a logical expression containing symbolic subexpressions, you can
get the symbolic constants symtrue and
symfalse. These
two constants are not the same as logical 1 (true) and logical 0 (false). To convert symbolic symtrue and
symfalse to logical values, use logical.
assume and assumeAlso do not accept assumptions
that contain xor.