combine

Combine terms of identical algebraic structure

Description

example

Y = combine(S) rewrites products of powers in the expression S as a single power.

example

Y = combine(S,T) combines multiple calls to the target function T in the expression S. Use combine to implement the inverse functionality of expand with respect to the majority of the applied rules.

example

Y = combine(___,'IgnoreAnalyticConstraints',true) simplifies the output by applying common mathematical identities, such as log(a) + log(b) = log(a*b). These identities might not be valid for all values of the variables, but applying them can return simpler results.

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

collapse all

Input expression, specified as a symbolic expression, function, or as a vector or matrix of symbolic expressions or functions.

combine works recursively on subexpressions of S.

If S is a symbolic matrix, combine is applied to all elements of the matrix.

Target function, specified as 'atan', 'exp', 'gamma', 'int', 'log', 'sincos', or 'sinhcosh'. The rewriting rules apply only to calls to the target function.

Output Arguments

collapse all

Expression with the combined functions, returned as a symbolic variable, number, expression, or as a vector or matrix of symbolic variables, numbers, or expressions.

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,

    eaeb=ea+b

    (ea)b=eab.

  • When T = 'log',

    log(a)+log(b)=log(ab).

    If b < 1000,

    blog(a)=log(ab).

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

    af(x)dx=af(x)dx

    f(x)dx+g(x)dx=f(x)+g(x)dx

    abf(x)dx+abg(x)dx=abf(x)+g(x)dx

    abf(x)dx+abg(y)dy=abf(y)+g(y)dy

    abyf(x)dx+abxg(y)dy=abyf(c)+xf(c)dc.

  • When T = 'sincos',

    sin(x)sin(y)=cos(xy)2cos(x+y)2.

    combine applies similar rules for sin(x)cos(y) and cos(x)cos(y).

    Acos(x)+Bsin(x)=A1+B2A2cos(x+tan1(BA)).

  • When T = 'atan' and -1 < x < 1, -1 < y < 1,

    atan(x)+atan(y)=atan(x+y1xy).

  • When T = 'sinhcosh',

    sinh(x)sinh(y)=cosh(x+y)2cosh(xy)2.

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

    aΓ(a)=Γ(a+1).

    and,

    Γ(a+1)Γ(a)=a.

    For positive integers n,

    Γ(a)Γ(a)=πsin(πa).

Introduced in R2014a