Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

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 |:

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 isAlways:

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

ans =
  logical
     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 isAlways:

isAlways(s1)
isAlways(s2)
ans =
  logical
     1

ans =
  logical
     0

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

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

More About

collapse 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 isAlways.

See Also

| | | | | |

Introduced in R2012a

Was this topic helpful?