Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Show assumptions affecting symbolic variable, expression, or function

`assumptions(var)`

`assumptions`

Assume that the variable `n`

is
an integer using `assume`

. Return the assumption
using `assumptions`

.

syms n assume(n,'integer') assumptions

ans = in(n, 'integer')

The syntax `in(n, 'integer')`

indicates `n`

is
an integer.

Assume that `n`

is less than `x`

and
that `x < 42`

using `assume`

.
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 = [ n < x, x < 42]

`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 = [ n < x, 1 < m, m < 3, x < 42]

To see the assumptions that affect all variables, use `assumptions`

without
any arguments.

assumptions

ans = [ n < x, 1 < m, m < 3, x < 42]

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 = [ in(x, 'real'), x < 0]

The syntax `in(x, 'real')`

indicates `x`

is `real`

.

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. Find
all assumptions that affect all variables in the symbolic expression
using `assumptions`

.

syms a b c expr = a*exp(b)*sin(c); assume(a+b > 3 & in(a,'integer') & in(c,'real')) assumptions(expr)

ans = [ 3 < a + b, in(a, 'integer'), in(c, 'real')

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

```
syms f(a,b,c)
assumptions(f)
```

ans = [ 3 < a + b, in(a, 'integer'), in(c, 'real')]

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 using `dsolve`

under
the assumptions that the mass and spring constant are `positive`

.

syms m k positive syms x(t) dsolve(m*diff(x,t,t) == -k*x, x(0)==0)

ans = C8*sin((k^(1/2)*t)/m^(1/2))

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')
dsolve(m*diff(x,t,t) == -k*x, x(0)==0)
```

ans = C10*exp((t*(-k*m)^(1/2))/m) + C10*exp(-(t*(-k*m)^(1/2))/m)

Restore the original assumptions using `assume`

.

assume(tmp)

After computations are complete, clear assumptions using `assume`

.

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

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 close the Symbolic Math Toolbox™ engine associated with the MATLAB workspace resetting all its assumptions, use this command.

reset(symengine)

Immediately before or after executing

`reset(symengine)`

you should clear all symbolic objects in the MATLAB workspace.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`

`and`

| `assume`

| `assumeAlso`

| `clear`

| ```
clear
all
```

| `in`

| `isAlways`

| `not`

| `or`

| `piecewise`

| `sym`

| `syms`

Was this topic helpful?