Main Content

or

Logical OR for symbolic expressions

Description

example

A | B represents the logical OR. A | B is true when either A or B is true, or when both A and B are true.

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

Examples

collapse all

Combine these symbolic inequalities into a logical condition by using |.

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

Set the assumption represented by the condition using assume.

assume(xy)

Verify that the assumptions are set.

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

Combine two symbolic inequalities into a logical expression by using |.

range = x < -1 | x > 1;

Substitute x with 0 and 10. Although the inequalities have values, subs does not evaluate them 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

Evaluate the inequalities by using isAlways.

isAlways(x1)
ans =
  logical
     1
isAlways(x2)
ans =
  logical
     0

Combine multiple conditions by applying or to the conditions using the fold function.

Set the condition that x equals an integer between 1 and 10.

syms x
cond = fold(@or, x == 1:10);
assume(cond)
assumptions
ans =
x == 1 | x == 2 | x == 3 | x == 4 | x == 5 |...
 x == 6 | x == 7 | x == 8 | x == 9 | x == 10

Input Arguments

collapse all

Operands, specified as symbolic equations, inequalities, expressions, or arrays. Inputs A and B must either be the same size or have sizes that are compatible (for example, A is an M-by-N matrix and B is a scalar or 1-by-N row vector). For more information, see Compatible Array Sizes for Basic Operations.

Tips

  • If 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.

Compatibility Considerations

expand all

Behavior changed in R2016b

See Also

| | | | | |

Introduced in R2012a