# symtrue

Symbolic logical constant true

## Description

example

symtrue is the symbolic logical constant for the true condition.

example

T = symtrue(n) returns an n-by-n matrix of symbolic logical symtrues.

example

T = symtrue(sz) returns an array of symbolic logical symtrues where the size vector, sz, defines size(T). For example, symtrue([2 3]) returns a 2-by-3 array of symbolic logical symtrues.

example

T = symtrue(sz1,...,szN) returns a sz1-by-...-by-szN array of symbolic logical symtrues where sz1,...,szN indicates the size of each dimension. For example, symtrue(2,3) returns a 2-by-3 array of symbolic logical symtrues.

## Examples

collapse all

Create a symbolic inequality ${x}^{2}>4$.

syms x
eq = x^2 > 4
eq = $4<{x}^{2}$

Assume that $x>2$.

assume(x>2)

Simplify the condition represented by the symbolic inequality eq. The simplify function returns the symbolic logical constant symtrue since the condition always holds for the assumption $x>2$.

T = simplify(eq)
T = $\mathrm{symtrue}$

Display the data type of T, which is sym.

class(T)
ans =
'sym'

You can also use isAlways to check if the inequality holds under the assumption being made. In this example, isAlways returns logical 1 (true).

TF = isAlways(eq)
TF = logical
1

Use symtrue to generate a 3-by-3 square matrix of symbolic logical symtrues.

T = symtrue(3)
T =

$\left(\begin{array}{ccc}\mathrm{symtrue}& \mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}& \mathrm{symtrue}\end{array}\right)$

Display the data type of T, which is sym.

class(T)
ans =
'sym'

Next, use symtrue to generate a 3-by-2-by-2 array of symbolic logical symtrue's.

T = symtrue(3,2,2)
T(:,:,1) =

$\left(\begin{array}{cc}\mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}\end{array}\right)$

T(:,:,2) =

$\left(\begin{array}{cc}\mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}\end{array}\right)$

Alternatively, you can use a size vector to specify the size of the array.

T = symtrue([3,2,2])
T(:,:,1) =

$\left(\begin{array}{cc}\mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}\end{array}\right)$

T(:,:,2) =

$\left(\begin{array}{cc}\mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}\\ \mathrm{symtrue}& \mathrm{symtrue}\end{array}\right)$

Create a truth table for the and operation applied to the two symbolic logical constants, symtrue and symfalse.

A = [symtrue symfalse]
A = $\left(\begin{array}{cc}\mathrm{symtrue}& \mathrm{symfalse}\end{array}\right)$
B = [symtrue; symfalse]
B =

$\left(\begin{array}{c}\mathrm{symtrue}\\ \mathrm{symfalse}\end{array}\right)$

TF = and(A,B)
TF =

$\left(\begin{array}{cc}\mathrm{symtrue}& \mathrm{symfalse}\\ \mathrm{symfalse}& \mathrm{symfalse}\end{array}\right)$

Combine symbolic logical constants with logical operators and, not, or, and xor (or their shortcuts).

TF = xor(symtrue,or(symfalse,symfalse))
TF = $\mathrm{symtrue}$
TF = symtrue & ~(symfalse)
TF = $\mathrm{symtrue}$

Convert the symbolic logical constant symtrue to a logical value.

T1 = logical(symtrue)
T1 = logical
1

Convert the symbolic logical constant symtrue to numeric values in double precision and variable precision.

T2 = double(symtrue)
T2 = 1
T3 = vpa(symtrue)
T3 = $1.0$

Show the data types of T1, T2, and T3.

whos
Name      Size            Bytes  Class      Attributes

T1        1x1                 1  logical
T2        1x1                 8  double
T3        1x1                 8  sym

## Input Arguments

collapse all

Size of square matrix, specified as an integer. n sets the output array size to n-by-n. For example, symtrue(3) returns a 3-by-3 array of symbolic logical symtrues.

• If n is 0, then T is an empty matrix.

• If n is negative, then it is treated as 0.

Size vector, specified as a row vector of integers. For example, symtrue([2 3]) returns a 2-by-3 array of symbolic logical symtrues.

• If the size of any dimension is 0, then T is an empty array.

• If the size of any dimension is negative, then it is treated as 0.

• If any trailing dimensions greater than 2 have a size of 1, then the output T does not include those dimensions. For example, symtrue([2 2 1 1]) returns a 2-by-2 array and symtrue([2 2 1 2 1]) returns a 2-by-2-by-1-by-2 array.

Size inputs, specified by a comma-separated list of integers. For example, symtrue(2,3) returns a 2-by-3 array of symbolic logical symtrues.

• If the size of any dimension is 0, then T is an empty array.

• If the size of any dimension is negative, then it is treated as 0.

• If any trailing dimensions greater than 2 have a size of 1, then the output T does not include those dimensions. For example, symtrue([2,2,1,1]) returns a 2-by-2 array and symtrue([2,2,1,2,1]) returns a 2-by-2-by-1-by-2 array.

## Output Arguments

collapse all

Symbolic logical constant for true condition, returned as a scalar, vector, matrix, or N-D array.

Data Types: sym

## Tips

• The command sym(true) returns a symbolic number 1, and sym(symtrue) returns symtrue.

• When you combine two arrays of symbolic logical constants with logical operations using and, or, or xor function, the arrays must either be the same size or have sizes that are compatible. For more information on the required input sizes for basic array operations, see Compatible Array Sizes for Basic Operations.

## Version History

Introduced in R2020a