or

Logical OR for symbolic expressions

Syntax

A | B
or(A,B)

Description

A | B represents the logical disjunction. A | B is true when either A or B or both are true.

or(A,B) is equivalent to A | B.

Input Arguments

A

Symbolic equation, inequality, or logical expression that contains symbolic subexpressions.

B

Symbolic equation, inequality, or logical expression that contains symbolic subexpressions.

Examples

Combine these symbolic inequalities into the logical expression using |:

syms x y
xy = x >= 0 | y >= 0;

Set the corresponding assumptions on variables x and y using assume:

assume(xy)

Verify that the assumptions are set:

assumptions
ans =
0 <= x | 0 <= y

Combine two symbolic inequalities into the logical expression using |:

syms x
range = x < -1 | x > 1;

Replace variable x with these numeric values. If you replace x with 10, one inequality is valid. If you replace x with 0, both inequalities are invalid. Note that subs does not evaluate these inequalities to logical 1 or 0.

x1 = subs(range, x, 10)
x2 = subs(range, x, 0)
x1 =
1 < 10 | 10 < -1
x2 =
0 < -1 | 1 < 0

To evaluate these inequalities to logical 1 or 0, use logical or isAlways:

logical(x1)
isAlways(x2)
ans =
     1

ans =
     0

Note that simplify does not simplify these logical expressions to logical 1 or 0. Instead, they return symbolic values TRUE or FALSE.

s1 = simplify(x1)
s2 = simplify(x2)
s1 =
TRUE
 
s2 =
FALSE

Convert symbolic TRUE or FALSE to logical values using logical:

logical(s1)
logical(s2)
ans =
     1

ans =
     0

More About

expand all

Tips

  • If you call simplify for a logical expression containing symbolic subexpressions, you can get symbolic values TRUE or FALSE. These values are not the same as logical 1 (true) and logical 0 (false). To convert symbolic TRUE or FALSE to logical values, use logical.

See Also

| | | | | |

Was this topic helpful?