assume
Set assumption on symbolic object
Description
assume(
sets mathematical
assumptions or conditions on symbolic variables as defined by
condition
)condition
. assume
is not additive. Instead, it
automatically deletes all previous assumptions on the variables in
condition
.
Examples
Common Assumptions
Set an assumption using the associated syntax.
Assumption for Symbolic Variable x | Syntax |
---|---|
real | assume(x,"real") |
rational | assume(x,"rational") |
positive | assume(x,"positive") |
positive integer | assume(x,{'positive','integer'}) |
less than –1 or greater than 1 | assume(x<-1 | x>1) |
an integer from 2 through 10 | assume(in(x,"integer") & x>2 & x<10) |
not an integer | assume(~in(z,"integer")) |
not equal to 0 | assume(x ~= 0) |
even | assume(x/2,"integer") |
odd | assume((x-1)/2,"integer") |
from 0 through 2π | assume(x>0 & x<2*pi) |
a multiple of π | assume(x/pi,"integer") |
Assume Variable Is Even or Odd
Assume x
is even by assuming that
x/2
is an integer. Assume x
is odd by assuming
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. assume
is not additive, but
instead automatically deletes the previous assumption in(x/2,
"integer")
.
assume((x-1)/2,"integer") solve(x>0,x<10,x)
ans = 1 3 5 7 9
Clear the assumptions on x
for further computations.
assume(x,"clear")
Multiple Assumptions
Successive assume
commands do not set multiple
assumptions. Instead, each assume
command deletes previous
assumptions and sets new assumptions. Set multiple assumptions by using
assumeAlso
or the &
operator.
Assume x > 5
and then x < 10
by using
assume
. Use assumptions
to check that only
the second assumption exists because assume
deleted the first
assumption when setting the second.
syms x assume(x > 5) assume(x < 10) assumptions
ans = x < 10
Assume the first assumption in addition to the second by using
assumeAlso
. Check that both assumptions exist.
assumeAlso(x > 5) assumptions
ans = [ 5 < x, x < 10]
Clear the assumptions on x
.
assume(x,"clear")
Assume both conditions using the &
operator. Check that both
assumptions exist.
assume(x>5 & x<10) assumptions
ans = [ 5 < x, x < 10]
Clear the assumptions on x
for future calculations.
assume(x,"clear")
Assumptions on Integrand
Compute an 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.
assume(a,"clear") int(x^a, x)
ans = piecewise(a == -1, log(x), a ~= -1, x^(a + 1)/(a + 1))
Assumptions on Parameters and Variables of Equation
Use assumptions to restrict the returned solutions of an equation to a particular interval.
Solve this equation.
syms x eqn = x^5 - (565*x^4)/6 - (1159*x^3)/2 - (2311*x^2)/6 + (365*x)/2 + 250/3; solve(eqn, 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(eqn, x)
ans = -1 -1/3 1/2
Set several assumptions simultaneously by using 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(eqn, x)
ans = -5 100
For further computations, clear the assumptions.
assume(x,"clear")
Use Assumptions for Simplification
Setting appropriate assumptions can result in simpler expressions.
Try to simplify the expression sin(2*pi*n)
using
simplify
. The simplify
function cannot
simplify the input and returns the input as it is.
syms n simplify(sin(2*n*pi))
ans = sin(2*pi*n)
Assume n
is an integer. simplify
now
simplifies the expression.
assume(n,"integer") simplify(sin(2*n*pi))
ans = 0
For further computations, clear the assumption.
assume(n,"clear")
Assumptions on Expressions
Set an assumption on a symbolic expression.
You can set assumptions not only on variables, but also on expressions. For example, compute this integral.
syms x f = 1/abs(x^2 - 1); int(f,x)
ans = -atanh(x)/sign(x^2 - 1)
Set the assumption x2 – 1 > 0 to produce a simpler result.
assume(x^2 - 1 > 0) int(f,x)
ans = -atanh(x)
For further computations, clear the assumption.
assume(x,"clear")
Assumptions to Prove Relations
Prove relations that hold under certain conditions by first assuming
the conditions and then using isAlways
.
Prove that sin(pi*x)
is never equal to 0
when
x
is not an integer. The isAlways
function
returns logical 1
(true
), which means the condition
holds for all values of x
under the set assumptions.
syms x assume(~in(x,"integer")) isAlways(sin(pi*x) ~= 0)
ans = logical 1
Assumptions on Matrix Elements
Set assumptions on all elements of a matrix using
sym
.
Create the 2-by-2 symbolic matrix A
with autogenerated elements.
Specify set
as rational
.
A = sym("A",[2 2],"rational")
A = [ A1_1, A1_2] [ A2_1, A2_2]
Return the assumptions on the elements of A
using
assumptions
.
assumptions(A)
ans = [ in(A1_1, 'rational'), in(A1_2, 'rational'),... in(A2_1, 'rational'), in(A2_2, 'rational')]
You can also use assume
to set assumptions on all elements of a
matrix. Now, assume all elements of A
have positive rational values.
Set the assumptions as a cell array of character vectors
{'positive','rational'}
.
assume(A,{'positive','rational'})
Return the assumptions on the elements of A
using
assumptions
.
assumptions(A)
ans = [ 0 < A1_1, 0 < A1_2, 0 < A2_1, 0 < A2_2,... in(A1_1, 'rational'), in(A1_2, 'rational'),... in(A2_1, 'rational'), in(A2_2, 'rational')]
For further computations, clear the assumptions.
assume(A,"clear")
Input Arguments
Tips
assume
removes any assumptions previously set on the symbolic variables. To retain previous assumptions while adding an assumption, useassumeAlso
.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
var
, use this command.assume(var,"clear")
To delete all objects in the MATLAB workspace and close the Symbolic Math Toolbox™ engine associated with the MATLAB workspace clearing all assumptions, use this command:
clear all
MATLAB projects complex numbers in inequalities to the real axis. 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 whether5 + i
is greater or less than2 + 3*i
.) For example,x > i
becomesx > 0
, andx <= 3 + 2*i
becomesx <= 3
.The toolbox does not support assumptions on symbolic functions. Set assumptions on symbolic variables and expressions instead.
When you create a new symbolic variable using
sym
andsyms
, you also can set an assumption that the variable is real, positive, integer, or rational.a = sym("a","real"); b = sym("b","rational"); c = sym("c","positive"); d = sym("d","positive"); e = sym("e",{'positive','integer'});
Alternatively, you can use these commands, which are more efficient.
syms a real syms b rational syms c d positive syms e positive integer
Version History
Introduced in R2012a