assumeAlso

Add assumption on symbolic object

Syntax

Description

example

assumeAlso(condition) states that condition is valid for all symbolic variables in condition. It retains all assumptions previously set on these symbolic variables.

example

assumeAlso(expr,set) states that expr belongs to set in addition to all previously made assumptions.

Examples

Assumptions Specified as Relations

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)
Warning: The solutions are valid under the following
conditions: x <= 1; x == 1. To include parameters and
conditions in the solution, specify the 'ReturnConditions'
option. 
> In solve>warnIfParams at 514
  In solve at 356 
s =
  (1 - x)^(1/2)*(x + 1)^(1/2)
 -(1 - x)^(1/2)*(x + 1)^(1/2) 

The solver warns that both solutions hold only under certain conditions. 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

Assumptions Specified as Sets

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

For further computations, clear the assumptions:

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

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 =
[ in(A1_1, 'rational'), in(A1_2, 'rational'), in(A1_3, 'rational'),...
 in(A2_1, 'rational'), in(A2_2, 'rational'), in(A2_3, 'rational'),...
 in(A3_1, 'rational'), in(A3_2, 'rational'), in(A3_3, 'rational'),...
 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

Contradicting Assumptions

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 =
[ in(y, 'real'), y ~= 0, in(y*i, 'real')]

For further computations, clear the assumptions:

syms y 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 assumeAlso(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

  • assumeAlso keeps all assumptions previously set on the symbolic variables. To replace previous assumptions with the new one, use assume.

  • When adding assumptions, always check that a new assumption does not contradict the existing assumptions. To see existing assumptions, use assumptions. Symbolic Math Toolbox™ does not guarantee to detect conflicting assumptions. Conflicting assumptions can lead to unpredictable and inconsistent results.

  • 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 later you 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 clear all objects in the MATLAB workspace and close the MuPAD® engine associated with the MATLAB workspace resetting all its 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.

  • Instead of adding assumptions one by one, you can set several assumptions in one function call. To set several assumptions, use assume and combine these assumptions by using the logical operators and, or, xor, not, all, any, or their shortcuts.

Was this topic helpful?