Expand expressions and simplify inputs of functions by using identities

collapse all in page

## Syntax

`expand(S)`

`expand(S,Name,Value)`

## Description

example

`expand(S)`

multiplies all parentheses in `S`

, and simplifies inputs to functions such as `cos(x + y)`

by applying standard identities.

example

`expand(S,Name,Value)`

uses additional options specified by one or more name-value pair arguments. For example, specifying `'IgnoreAnalyticConstraints'`

as `true`

uses convenient identities to simplify the input.

## Examples

collapse all

### Expand Symbolic Expression

syms xp = (x - 2)*(x - 4);expand(p)

ans =x^2 - 6*x + 8

### Expand Trigonometric Expression

Expand the trigonometric expression `cos(x + y)`

. Simplify the `cos`

function input `x + y`

to `x`

or `y`

by applying standard identities.

syms x yexpand(cos(x + y))

### Expand Exponential Expression

Expand e^{(a+b)2}. Simplify the `exp`

function input, `(a + b)^2`

, by applying standard identities.

syms a bf = exp((a + b)^2);expand(f)

ans =exp(a^2)*exp(b^2)*exp(2*a*b)

### Expand Vector of Expressions

Expand expressions in a vector. Simplify the inputs to functions in the expressions by applying identities.

syms tV = [sin(2*t), cos(2*t)];expand(V)

ans =[ 2*cos(t)*sin(t), 2*cos(t)^2 - 1]

### Expand Only Arithmetic and Suppress Expansion of Functions

By default, `expand`

both expands terms raised to powers and expands functions by applying identities that simplify inputs to the functions. Expand only terms raised to powers and suppress expansion of functions by using `'ArithmeticOnly'`

.

Expand `(sin(3*x) - 1)^2`

. By default, `expand`

will expand the power `^2`

and simplify the `sin`

input `3*x`

to `x`

.

syms xf = (sin(3*x) - 1)^2;expand(f)

ans =2*sin(x) + sin(x)^2 - 8*cos(x)^2*sin(x) - 8*cos(x)^2*sin(x)^2... + 16*cos(x)^4*sin(x)^2 + 1

Suppress expansion of functions, such as `sin(3*x)`

, by setting `ArithmeticOnly`

to `true`

.

expand(f, 'ArithmeticOnly', true)

ans =sin(3*x)^2 - 2*sin(3*x) + 1

### Simplify Log Input by Removing Constraints

Simplify the input of `log`

function calls. By default, `expand`

does not simplify logarithm input because the identities used are not valid for complex values of variables.

syms a b cf = log((a*b/c)^2);expand(f)

ans =log((a^2*b^2)/c^2)

Apply identities to simplify the input of logarithms by setting `'IgnoreAnalyticConstraints'`

to `true`

.

expand(f,'IgnoreAnalyticConstraints',true)

ans = 2*log(a) + 2*log(b) - 2*log(c)

## Input Arguments

collapse all

`S`

— Input

number | vector | matrix | array | symbolic number | symbolic variable | symbolic array | symbolic function | symbolic expression

Input, specified as a number, vector, matrix, or array, or a symbolic number, variable, array, function, or expression.

### Name-Value Arguments

Specify optional pairs of arguments as `Name1=Value1,...,NameN=ValueN`

, where `Name`

is the argument name and `Value`

is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

* Before R2021a, use commas to separate each name and value, and enclose* `Name`

*in quotes.*

**Example: **`expand(S,'ArithmeticOnly',true)`

`ArithmeticOnly`

— Expand only algebraic expressions

`false`

(default) | `true`

Expand only algebraic expressions, specified as the comma-separated pair consisting of `'ArithmeticOnly'`

and `true`

or `false`

. If the value is `true`

, the function expands the arithmetic part of an expression without expanding trigonometric, hyperbolic, logarithmic, and special functions. This option does not prevent the expansion of powers and roots.

`IgnoreAnalyticConstraints`

— Use convenient identities for simplification

`false`

(default) | true

Use convenient identities for simplification, specified as the comma-separated pair consisting of `'IgnoreAnalyticConstraints'`

and `true`

or `false`

.

Setting `'IgnoreAnalyticConstraints'`

to `true`

can give you simpler solutions, which could lead to results not generally valid. In other words, this option applies mathematical identities that are convenient, but the results might not hold for all values of the variables. In some cases, this option can let `expand`

return simpler results that might not be equivalent to the initial expression. See Algorithms.

## Algorithms

When you use `'IgnoreAnalyticConstraints'`

, `expand`

applies some of these rules.

log(

*a*) + log(*b*)=log(*a*·*b*) for all values of*a*and*b*. In particular, the following equality is valid for all values of*a*,*b*, and*c*:(

*a*·*b*)^{c}=*a*^{c}·*b*^{c}.log(

*a*^{b})=*b*·log(*a*) for all values of*a*and*b*. In particular, the following equality is valid for all values of*a*,*b*, and*c*:(

*a*^{b})^{c}=*a*^{b·c}.If

*f*and*g*are standard mathematical functions and*f*(*g*(*x*))=*x*for all small positive numbers,*f*(*g*(*x*))=*x*is assumed to be valid for all complex*x*.log(

*e*^{x})=*x*asin(sin(

*x*))=*x*, acos(cos(*x*))=*x*, atan(tan(*x*))=*x*asinh(sinh(

*x*))=*x*, acosh(cosh(*x*))=*x*, atanh(tanh(*x*))=*x*W

_{k}(*x*·*e*^{x})=*x*for all values of*k*

## Version History

**Introduced before R2006a**

## See Also

### Functions

- collect | combine | factor | horner | numden | rewrite | simplify | simplifyFraction

### Live Editor Tasks

- Simplify Symbolic Expression

### Topics

- Choose Function to Rearrange Expression
- Simplify Symbolic Expressions
- Simplify Symbolic Expressions Using Live Editor Task

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français

- United Kingdom (English)

Contact your local office