Main Content

assumptions

Show assumptions affecting symbolic variable, expression, or function

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 = nZ

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 = (n<xx<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<x1<mm<3x<42)

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

assumptions
ans = (n<x1<mm<3x<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 = (xRx<0)

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 = (aZcR3<a+b)

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

assumptions(f)
ans = (aZcR3<a+b)

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 = (aZcR3<a+b)

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 = 

-C1sin(ktm)

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 = 

-C1e-t-kmme2t-kmm-1

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