and

Logical AND for symbolic expressions

Description

example

A & B represents the logical AND. A & B is true only when both A and B are true.

and(A,B) is equivalent to A & B.

Examples

collapse all

Combine symbolic inequalities into one condition by using &.

syms x y
cond = x>=0 & y>=0;

Set the assumptions represented by the condition using assume.

assume(cond)

Verify that the assumptions are set.

assumptions
ans =
[ 0 <= x, 0 <= y]

Define a range for a variable by combining two inequalities into a logical condition using &.

syms x
range = 0 < x & x < 1;

Return the condition at 1/2 and 10 by substituting for x using subs. The subs function does not evaluate the conditions automatically.

x1 = subs(range,x,1/2)
x2 = subs(range,x,10)
x1 =
0 < 1/2 & 1/2 < 1
x2 =
0 < 10 & 10 < 1

Evaluate the inequalities to logical 1 or 0 by using isAlways.

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

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