Main Content

# combine

Combine terms of identical algebraic structure

## Syntax

``Y = combine(S)``
``Y = combine(S,T)``
``Y = combine(___,'IgnoreAnalyticConstraints',true)``

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

`${e}^{a}{e}^{b}={e}^{a+b}$`

`${\left({e}^{a}\right)}^{b}={e}^{ab}.$`

• When T = `'log'`,

`$\mathrm{log}\left(a\right)+\mathrm{log}\left(b\right)=\mathrm{log}\left(ab\right).$`

If b < 1000,

`$b\mathrm{log}\left(a\right)=\mathrm{log}\left({a}^{b}\right).$`

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

`$a\int f\left(x\right)dx=\int af\left(x\right)dx$`

`$\int f\left(x\right)dx+\int g\left(x\right)dx=\int f\left(x\right)+g\left(x\right)dx$`

`${\int }_{a}^{b}f\left(x\right)dx+{\int }_{a}^{b}g\left(x\right)dx={\int }_{a}^{b}f\left(x\right)+g\left(x\right)dx$`

`${\int }_{a}^{b}f\left(x\right)dx+{\int }_{a}^{b}g\left(y\right)dy={\int }_{a}^{b}f\left(y\right)+g\left(y\right)dy$`

`${\int }_{a}^{b}yf\left(x\right)dx+{\int }_{a}^{b}xg\left(y\right)dy={\int }_{a}^{b}yf\left(c\right)+xg\left(c\right)dc.$`

• When T = `'sincos'`,

`$\mathrm{sin}\left(x\right)\mathrm{sin}\left(y\right)=\frac{\mathrm{cos}\left(x-y\right)}{2}-\frac{\mathrm{cos}\left(x+y\right)}{2}.$`

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

`$A\mathrm{cos}\left(x\right)+B\mathrm{sin}\left(x\right)=A\sqrt{1+\frac{{B}^{2}}{{A}^{2}}}\mathrm{cos}\left(x+{\mathrm{tan}}^{-1}\left(\frac{-B}{A}\right)\right).$`

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

`$\mathrm{atan}\left(x\right)+\mathrm{atan}\left(y\right)=\mathrm{atan}\left(\frac{x+y}{1-xy}\right).$`

• When T = `'sinhcosh'`,

`$\mathrm{sinh}\left(x\right)\mathrm{sinh}\left(y\right)=\frac{\mathrm{cosh}\left(x+y\right)}{2}-\frac{\mathrm{cosh}\left(x-y\right)}{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\Gamma \left(a\right)=\Gamma \left(a+1\right).$`

and,

`$\frac{\Gamma \left(a+1\right)}{\Gamma \left(a\right)}=a.$`

For positive integers `n`,

`$\Gamma \left(-a\right)\Gamma \left(a\right)=-\frac{\pi }{\mathrm{sin}\left(\pi a\right)}.$`

Introduced in R2014a

## Support

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos