Combine terms of identical algebraic structure
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
.
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
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)
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)
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)
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)
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
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.
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)]
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
and b
. Specify
appropriate properties for a
or b
to
enable these rewriting rules.
When T = 'int'
,
When T = 'sincos'
,
combine
applies similar rules for sin(x)cos(y)
and cos(x)cos(y)
.
When T = 'atan'
and -1
< x < 1, -1
< y < 1,
When T = 'sinhcosh'
,
combine
applies similar rules for sinh(x)cosh(y)
and cosh(x)cosh(y)
.
combine
applies the previous rules recursively
to powers of sinh
and cosh
with
positive integral exponents.
When T = 'gamma'
,
and,
For positive integers n
,