assumptions

Show assumptions affecting symbolic variable, expression, or function

Syntax

``assumptions(var)``
``assumptions``

Description

example

````assumptions(var)` returns all assumptions that affect variable `var`. If `var` is an expression or function, `assumptions` returns all assumptions that affect all variables in `var`.```

example

````assumptions` returns all assumptions that affect all variables in MATLAB® Workspace.```

Examples

collapse all

In Symbolic Math Toolbox™, you can set mathematical assumptions or conditions when creating symbolic variables. For example, create a symbolic variable `n` and assume that the variable is an integer. Return the assumption using `assumptions`.

```syms n integer assumptions```
`ans = $n\in \mathbb{Z}$`

You can also use the `assume` function to set assumptions. For example, assume that `n` is less than `x` and that `x < 42`. The `assume` function replaces old assumptions on input with the new assumptions. Return all assumptions that affect `n`.

```syms x assume(n < x & x < 42) assumptions(n)```
`ans = $\left(\begin{array}{cc}n`

`assumptions` returns the assumption `x < 42` because it affects `n` through the assumption `n < x`. Thus, `assumptions` returns the transitive closure of assumptions, which is all assumptions that mathematically affect the input.

Set the assumption on variable `m` that `1 < m < 3`. Return all assumptions on `m` and `x` using `assumptions`.

```syms m assume(1 < m < 3) assumptions([m x])```
`ans = $\left(\begin{array}{cccc}n`

To see the assumptions that affect all variables, use `assumptions` without any arguments.

`assumptions`
`ans = $\left(\begin{array}{cccc}n`

For further computations, clear the assumptions.

`assume([m n x],"clear")`

You cannot set an additional assumption on a variable using `assume` because `assume` clears all previous assumptions on that variable. To set an additional assumption on a variable, using `assumeAlso`.

Set an assumption on `x` using `assume`. Set an additional assumption on `x` use `assumeAlso`. Use `assumptions` to return the multiple assumptions on `x`.

```syms x assume(x,"real") assumeAlso(x < 0) assumptions(x)```
`ans = $\left(\begin{array}{cc}x\in \mathbb{R}& x<0\end{array}\right)$`

For further computations, clear the assumptions.

`assume(x,"clear")`

`assumptions` accepts symbolic expressions and functions as input and returns all assumptions that affect all variables in the symbolic expressions or functions.

Set assumptions on variables in a symbolic expression and function. Find all assumptions that affect all variables in the symbolic expression using `assumptions`.

```syms a b c f(a,b,c) expr = a*exp(b)*sin(c); assume(a+b > 3 & in(a,"integer") & in(c,"real")) assumptions(expr)```
`ans = $\left(\begin{array}{ccc}a\in \mathbb{Z}& c\in \mathbb{R}& 3`

Find all assumptions that affect all variables that are inputs to a symbolic function.

`assumptions(f)`
`ans = $\left(\begin{array}{ccc}a\in \mathbb{Z}& c\in \mathbb{R}& 3`

Note that if you use `syms` to create another symbolic function after setting assumptions on the function input arguments, `syms` clears all previously set assumptions on the symbolic variables. Instead, create the symbolic function first, and then set the assumptions on the symbolic variables.

```syms g(a,b,c) assumptions(g)```
``` ans = Empty sym: 1-by-0 ```
```assume(a+b > 3 & in(a,"integer") & in(c,"real")) assumptions(g)```
`ans = $\left(\begin{array}{ccc}a\in \mathbb{Z}& c\in \mathbb{R}& 3`

Clear the assumptions for further computations.

`assume([a b c],"clear")`

To restore old assumptions, first store the assumptions returned by `assumptions`. Then you can restore these assumptions at any point by calling `assume` or `assumeAlso`.

Solve the equation for a spring system using `dsolve` under the assumptions that the mass and spring constant are `positive`.

```syms m k positive syms x(t) xsol = dsolve(m*diff(x,t,t) == -k*x, x(0) == 0)```
```xsol =  $-{C}_{1} \mathrm{sin}\left(\frac{\sqrt{k} t}{\sqrt{m}}\right)$```

Suppose you want to explore solutions unconstrained by assumptions, but want to restore the assumptions afterwards. First store the assumptions using `assumptions`, then clear the assumptions and solve the equation. `dsolve` returns unconstrained solutions.

```tmp = assumptions; assume([m k],"clear") xsol = dsolve(m*diff(x,t,t) == -k*x, x(0) == 0)```
```xsol =  $-{C}_{1} {\mathrm{e}}^{-\frac{t \sqrt{-k m}}{m}} \left({\mathrm{e}}^{\frac{2 t \sqrt{-k m}}{m}}-1\right)$```

Restore the original assumptions using `assume`.

`assume(tmp)`

After computations are complete, clear assumptions using `assume`.

`assume([m k],"clear")`

Input Arguments

collapse all

Symbolic input for which to show assumptions, specified as a symbolic variable, expression, or function, or a vector, matrix, or multidimensional array of symbolic variables, expressions, or functions.

Tips

• When you delete a symbolic object from the MATLAB workspace by using `clear`, all assumptions that you set on that object remain in the symbolic engine. If you declare a new symbolic variable with the same name, it inherits these assumptions.

• To clear all assumptions set on a symbolic variable `var` use this command.

`assume(var,"clear")`
• To clear all objects in the MATLAB workspace and close the Symbolic Math Toolbox™ engine associated with the MATLAB workspace resetting all its assumptions, use this command.

`clear all`

Version History

Introduced in R2012a