combine
Combine terms of identical algebraic structure
Description
Examples
Powers of the Same Base
Combine powers of the same base.
syms x y z combine(x^y*x^z)
ans = x^(y + z)
Combine powers of numeric arguments. To prevent MATLAB® from evaluating the expression, use sym
to
convert at least one numeric argument into a symbolic value.
syms x y combine(x^(3)*x^y*x^exp(sym(1)))
ans = x^(y + exp(1) + 3)
Here, sym
converts 1
into a symbolic value,
preventing MATLAB from evaluating the expression
e1
.
Powers of the Same Exponent
Combine powers with the same exponents in certain cases.
combine(sqrt(sym(2))*sqrt(3))
ans = 6^(1/2)
combine
does not usually combine the powers because the
internal simplifier applies the same rules in the opposite direction to expand the
result.
syms x y combine(y^5*x^5)
ans = x^5*y^5
Terms with Logarithms
Combine terms with logarithms by specifying the target
argument as log
. For real positive numbers, the logarithm of
a product equals the sum of the logarithms of its factors.
S = log(sym(2)) + log(sym(3)); combine(S,'log')
ans = log(6)
Try combining log(a) + log(b)
. Because a
and
b
are assumed to be complex numbers by default, the rule does
not hold and combine
does not combine the terms.
syms a b S = log(a) + log(b); combine(S,'log')
ans = log(a) + log(b)
Apply the rule by setting assumptions such that a
and
b
satisfy the conditions for the rule.
assume(a > 0) assume(b > 0) S = log(a) + log(b); combine(S,'log')
ans = log(a*b)
For future computations, clear the assumptions set on variables a and b by
recreating them using syms
.
syms a b
Alternatively, apply the rule by ignoring analytic constraints using
'IgnoreAnalyticConstraints'
.
syms a b S = log(a) + log(b); combine(S,'log','IgnoreAnalyticConstraints',true)
ans = log(a*b)
Terms with Sine and Cosine Function Calls
Rewrite products of sine and cosine functions as a sum of the
functions by setting the target argument to sincos
.
syms a b combine(sin(a)*cos(b) + sin(b)^2,'sincos')
ans = sin(a + b)/2 - cos(2*b)/2 + sin(a - b)/2 + 1/2
Rewrite sums of sine and cosine functions by setting the target argument to
sincos
.
combine(cos(a) + sin(a),'sincos')
ans = 2^(1/2)*cos(a - pi/4)
Rewrite a cosine squared function by setting the target argument to
sincos
.
combine(cos(a)^2,'sincos')
ans = cos(2*a)/2 + 1/2
combine
does not rewrite powers of sine or cosine functions
with negative integer exponents.
syms a b combine(sin(b)^(-2)*cos(b)^(-2),'sincos')
ans = 1/(cos(b)^2*sin(b)^2)
Exponential Terms
Combine terms with exponents by specifying the target
argument as exp
.
combine(exp(sym(3))*exp(sym(2)),'exp')
ans = exp(5)
syms a combine(exp(a)^3, 'exp')
ans = exp(3*a)
Terms with Integrals
Combine terms with integrals by specifying the target
argument as int
.
syms a f(x) g(x) combine(int(f(x),x)+int(g(x),x),'int') combine(a*int(f(x),x),'int')
ans = int(f(x) + g(x), x) ans = int(a*f(x), x)
Combine integrals with the same limits.
syms a b h(z) combine(int(f(x),x,a,b)+int(h(z),z,a,b),'int')
ans = int(f(x) + h(x), x, a, b)
Terms with Inverse Tangent Function Calls
Combine two calls to the inverse tangent function by
specifying the target argument as atan
.
syms a b assume(-1 < a < 1) assume(-1 < b < 1) combine(atan(a) + atan(b),'atan')
ans = -atan((a + b)/(a*b - 1))
Combine two calls to the inverse tangent function. combine
simplifies the expression to a symbolic value if possible.
assume(a > 0) combine(atan(a) + atan(1/a),'atan')
ans = pi/2
For further computations, clear the assumptions:
syms a b
Terms with Calls to Gamma Function
Combine multiple gamma functions by specifying the target as
gamma
.
syms x combine(gamma(x)*gamma(1-x),'gamma')
ans = -pi/sin(pi*(x - 1))
combine
simplifies quotients of gamma functions to rational
expressions.
Multiple Input Expressions in One Call
Evaluate multiple expressions in one function call by using a symbolic matrix as the input parameter.
S = [sqrt(sym(2))*sqrt(5), sqrt(2)*sqrt(sym(11))]; combine(S)
ans = [ 10^(1/2), 22^(1/2)]
Input Arguments
Output Arguments
Algorithms
combine
applies the following rewriting rules to the input
expression S
, depending on the value of the target argument
T
.
When T =
'exp'
,combine
applies these rewriting rules where valid,When T =
'log'
,If b < 1000,
When
b >= 1000
,combine
does not apply this second rule.The rules applied to rewrite logarithms do not hold for arbitrary complex values of
a
andb
. Specify appropriate properties fora
orb
to enable these rewriting rules.When T =
'int'
,When T =
'sincos'
,combine
applies similar rules forsin(x)cos(y)
andcos(x)cos(y)
.When T =
'atan'
and -1 < x < 1, -1 < y < 1,When T =
'sinhcosh'
,combine
applies similar rules forsinh(x)cosh(y)
andcosh(x)cosh(y)
.combine
applies the previous rules recursively to powers ofsinh
andcosh
with positive integral exponents.When T =
'gamma'
,and,
For positive integers
n
,
Version History
Introduced in R2014a