## Documentation Center |

Add assumption on symbolic object

Set assumptions using `assume`.
Then add more assumptions using `assumeAlso`.

Solve this equation assuming that both `x` and `y` are
nonnegative:

syms x y assume(x >= 0 & y >= 0) s = solve(x^2 + y^2 == 1, y)

s = {[(- x + 1)^(1/2)*(x + 1)^(1/2), 1],... [-(- x + 1)^(1/2)*(x + 1)^(1/2), 1]} intersect... Dom::Interval([0], Inf)

Now add the assumption that `x < 1`. To
add a new assumption without removing the previous one, use `assumeAlso`:

assumeAlso(x < 1)

Solve the same equation under the expanded set of assumptions:

s = solve(x^2 + y^2 == 1, y)

s = (1 - x)^(1/2)*(x + 1)^(1/2)

For further computations, clear the assumptions:

syms x y clear

Set assumptions using `syms`.
Then add more assumptions using `assumeAlso`.

When declaring the symbolic variable `n`, set
an assumption that `n` is positive:

syms n positive

Using `assumeAlso`, you can add more assumptions
on the same variable `n`. For example, assume also
that n is and integer:

assumeAlso(n,'integer')

To see all assumptions currently valid for the variable `n`,
use `assumptions`. In this case, `n` is
a positive integer.

assumptions(n)

ans = [ n in Z_, 0 < n]

For further computations, clear the assumptions:

syms n clear

Use the assumption on a matrix as a shortcut for setting the same assumption on each matrix element.

Create the 3-by-3 symbolic matrix `A` with
the auto-generated elements:

A = sym('A', [3 3])

A = [ A1_1, A1_2, A1_3] [ A2_1, A2_2, A2_3] [ A3_1, A3_2, A3_3]

Suppose that all elements of this matrix represent rational numbers. Instead of setting an assumption on each element separately, you can set the assumption on the matrix:

assume(A,'rational')

Now, add the assumption that each element of `A` is
greater than 1:

assumeAlso(A > 1)

To see the assumptions on the elements of `A`,
use `assumptions`:

assumptions(A)

ans = [ A1_1 in Q_, A1_2 in Q_, A1_3 in Q_, A2_1 in Q_, A2_2 in Q_,... A2_3 in Q_, A3_1 in Q_, A3_2 in Q_, A3_3 in Q_,... 1 < A1_1, 1 < A1_2, 1 < A1_3, 1 < A2_1, 1 < A2_2, 1 < A2_3,... 1 < A3_1, 1 < A3_2, 1 < A3_3]

For further computations, clear the assumptions:

syms A clear

When you add assumptions, ensure that the new assumptions do not contradict the previous assumptions. Contradicting assumptions can lead to inconsistent and unpredictable results.

In some cases, `assumeAlso` detects conflicting
assumptions and issues the following error:

syms y assume(y,'real') assumeAlso(y == i)

Error using mupadmex Error in MuPAD command: Inconsistent assumptions detected. [property::_setgroup]

`assumeAlso` does not guarantee to detect contradicting
assumptions. For example, you can assume that `y` is
nonzero, and both `y` and `y*i` are
real values:

syms y assume(y ~= 0) assumeAlso(y,'real') assumeAlso(y*i,'real')

To see all assumptions currently valid for the variable `y`,
use `assumptions`:

assumptions(y)

ans = [ y in R_, y ~= 0, y*i in R_]

For further computations, clear the assumptions:

syms y clear

`and` | `assume` | `assumptions` | `clear all` | `isAlways` | `logical` | `not` | `or` | `sym` | `syms`

Was this topic helpful?