assume

Set assumption on symbolic object

Syntax

Description

example

assume(condition) states that condition is valid for all symbolic variables in condition. It also removes any assumptions previously made on these symbolic variables.

example

assume(expr,set) states that expr belongs to set. This new assumption replaces previously set assumptions on all variables in expr.

Examples

Assumptions on Integrand

Compute this indefinite integral with and without the assumption on the symbolic parameter a.

Use assume to set an assumption that a does not equal -1:

syms x a
assume(a ~= -1)

Compute this integral:

int(x^a, x)
ans =
x^(a + 1)/(a + 1)

Now, clear the assumption and compute the same integral. Without assumptions, int returns this piecewise result:

syms a clear
int(x^a, x)
ans =
piecewise([a == -1, log(x)], [a ~= -1, x^(a + 1)/(a + 1)])

Assume Variable is Even or Odd

To assume the symbolic variable x is even, set the assumption that x/2 is an integer. To assume x is odd, set the assumption that (x-1)/2 is an integer.

Assume x is even.

syms x
assume(x/2,'integer')

Find all even numbers between 0 and 10 using solve.

solve(x>0, x<10, x)
ans =
 2
 4
 6
 8

Assume x is odd. Find all odd numbers between 0 and 10 using solve.

assume((x-1)/2,'integer')
solve(x>0, x<10, x)
ans =
 1
 3
 5
 7
 9

Clear assumptions on x for further computations.

syms x clear

Assumptions on Parameters and Variables of Equation

Use assumptions on the symbolic parameter and variable in the kinematic equation for the free fall motion.

Calculate the time during which the object falls from a certain height by solving the kinematic equation for the free fall motion. If you do not consider the special case where no gravitational forces exist, you can assume that the gravitational acceleration g is positive:

syms g h t
assume(g > 0)
solve(h == g*t^2/2, t)
ans =
  (2^(1/2)*h^(1/2))/g^(1/2)
 -(2^(1/2)*h^(1/2))/g^(1/2)

You can also set assumptions on variables for which you solve an equation. When you set assumptions on such variables, the solver compares obtained solutions with the specified assumptions. This additional task can slow down the solver.

assume(t > 0)
solve(h == g*t^2/2, t)
Warning: The solutions are valid under the following
conditions: 0 < h. To include parameters and conditions in
the solution, specify the 'ReturnConditions' option. 
> In solve>warnIfParams at 514
  In solve at 356 
ans =
(2^(1/2)*h^(1/2))/g^(1/2)

The solver returns a warning that h must be positive. This follows as the object is above ground.

For further computations, clear the assumptions:

syms g t clear

Assumptions Used for Simplification

Use assumption to simplify the sine function.

Simplify this sine function:

syms n
simplify(sin(2*n*pi))
ans =
sin(2*pi*n)

Suppose n in this expression is an integer. Then you can simplify the expression further using the appropriate assumption:

assume(n,'integer')
simplify(sin(2*n*pi))
ans =
0

For further computations, clear the assumption:

syms n clear

Assumptions on Expressions

Set assumption on the symbolic expression.

You can set assumptions not only on variables, but also on expressions. For example, compute this integral:

syms x
int(1/abs(x^2 - 1), x)
ans =
-atanh(x)/sign(x^2 - 1)

If you know that x2 – 1 > 0, set the appropriate assumption:

assume(x^2 - 1 > 0)
int(1/abs(x^2 - 1), x)
ans =
-atanh(x)

For further computations, clear the assumption:

syms x clear

Assumptions Reducing Number of Solutions

Use assumptions to restrict the returned solutions of an equation to a particular interval.

Solve this equation:

syms x
solve(x^5 - (565*x^4)/6 - (1159*x^3)/2 - (2311*x^2)/6 + (365*x)/2 + 250/3, x)
ans =
   -5
   -1
 -1/3
  1/2
  100

Use assume to restrict the solutions to the interval –1 <= x <= 1:

assume(-1 <= x <= 1)
solve(x^5 - (565*x^4)/6 - (1159*x^3)/2 - (2311*x^2)/6 + (365*x)/2 + 250/3, x)
ans =
   -1
 -1/3
  1/2

To set several assumptions simultaneously, use the logical operators and, or, xor, not, or their shortcuts. For example, all negative solutions less than -1 and all positive solutions greater than 1:

assume(x < -1 | x > 1)
solve(x^5 - (565*x^4)/6 - (1159*x^3)/2 - (2311*x^2)/6 + (365*x)/2 + 250/3, x)
ans =
  -5
 100

For further computations, clear the assumptions:

syms x clear

Assumptions on Matrix Elements

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')

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

assumptions(A)
ans =
[ in(A3_1, 'rational'), in(A2_1, 'rational'), in(A1_1, 'rational'),...
 in(A3_2, 'rational'), in(A2_2, 'rational'), in(A1_2, 'rational'),...
 in(A3_3, 'rational'), in(A2_3, 'rational'), in(A1_3, 'rational')]

For further computations, clear the assumptions:

syms A clear

Input Arguments

expand all

condition — Assumption statementsymbolic expression | symbolic equation | relation | vector of symbolic expressions, equations, or relations | matrix of symbolic expressions, equations, or relations

Assumption statement, specified as a symbolic expression, equation, relation, or vector or matrix of symbolic expressions, equations, or relations. You also can combine several assumptions by using the logical operators and, or, xor, not, or their shortcuts.

expr — Expression to set assumption onsymbolic variable | symbolic expression | vector | matrix

Expression to set assumption on, specified as a symbolic variable, expression, vector, or matrix. If expr is a vector or matrix, then assume(expr,set) sets an assumption that each element of expr belongs to set.

set — Set of integer, rational, or real numbers'integer' | 'rational' | 'real'

Set of integer, rational, or real numbers, specified as one of these strings: 'integer', 'rational', or 'real'.

More About

expand all

Tips

  • assume removes any assumptions previously set on the symbolic variables. To retain previous assumptions while adding a new one, use assumeAlso.

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

  • To clear all assumptions set on a symbolic variable and the value of the variable, use this command:

     syms x clear
  • To clear assumptions and keep the value of the variable, use this command:

    sym('x','clear')
  • To delete all objects in the MATLAB workspace and close the MuPAD® engine associated with the MATLAB workspace clearing all assumptions, use this command:

    clear all
  • If condition is an inequality, then both sides of the inequality must represent real values. Inequalities with complex numbers are invalid because the field of complex numbers is not an ordered field. (It is impossible to tell whether 5 + i is greater or less than 2 + 3*i.) MATLAB projects complex numbers in inequalities to real axis. For example, x > i becomes x > 0, and x <= 3 + 2*i becomes x <= 3.

  • The toolbox does not support assumptions on symbolic functions. Make assumptions on symbolic variables and expressions instead.

  • When you create a new symbolic variable using sym and syms, you also can set an assumption that the variable is real or positive:

    a = sym('a','real');
    b = sym('b','real');
    c = sym('c','positive');

    or more efficiently

    syms a b real
    syms c positive
Was this topic helpful?