Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

## Choose Simplification Functions

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Most mathematical expressions can be represented in different, but mathematically equivalent forms. Some of these forms might look simpler, for example, they can be visibly shorter. However, you might prefer other forms of the same expression for numeric computations. There is no general rule as to which form of an expression is the simplest. When solving a particular problem, you can choose the simplest form of an expression for this problem.

Besides the general simplification functions `simplify` and `Simplify`, MuPAD® provides a set of functions for transforming mathematical expressions to particular forms. The following table helps you choose the function for transforming your expression to the appropriate form. To see a short description of a function and a set of examples, click the link in the left column. To see the detailed help page for a function, click the function name in the right column.

### Collect Terms with Same Powers

If a mathematical expression contains terms with the same powers of a specified variable or expression, the `collect` function reorganizes the expression grouping such terms. When calling `collect`, specify the variables or expressions that the function must consider as unknowns. The `collect` function regards the original expression as a polynomial in the specified unknowns, and groups the coefficients with equal powers:

```collect(x*y^4 + x*z + 2*x^3 + x^2*y*z + 3*x^3*y^4*z^2 + y*z^2 + 5*x*y*z, x)```

`collect` can consider an expression as the specified unknown. For example, group the terms of the following trigonometric expression with the equal powers of `sin(x)` and `cos(x)`:

```f := cos(x)^4*sin(x) + cos(x)^2*sin(x)^3 + cos(x)^2*sin(x)^2 - sin(x)^4: collect(f, sin(x))```

`collect(f, cos(x))`

The `collect` function also can accept several unknowns for collecting terms. If you have several unknowns, pass them to `collect` as a list:

```collect(a^2*sin(x) - cos(x)^2*sin(x)^3 + cos(x)^2 + a - a^2*sin(x)^4, [a, cos(x)])```

### Combine Terms of Same Algebraic Structures

MuPAD also provides a function for combining subexpressions of an original expression. The `combine` function uses mathematical identities for the functions you indicate. For example, combine the trigonometric expression:

`combine(2*sin(x)*cos(x), sincos)`

If you do not specify a target function, `combine` uses the identities for powers wherever these identities are valid:

• abac = ab + c

• acbc = (ab)c, if `c` is an integer

• (ab)c = abc, if `c` is an integer

For example, by default the function combines the following square roots:

`combine(sqrt(2)*sqrt(x))`

The function does not combine these square roots because the identity is not valid for negative values of variables:

`combine(sqrt(x)*sqrt(y))`

To combine these square roots, use the `IgnoreAnalyticConstraints` option:

`combine(sqrt(x)*sqrt(y), IgnoreAnalyticConstraints)`

As target functions, `combine` accepts `arctan`, `exp`, `gamma`, `ln`, `sincos`, and other functions. For the complete list of target functions, see the `combine` help page.

### Expand Expressions

For elementary expressions, the `expand` function transforms the original expression by multiplying sums of products:

`expand((x + 1)*(x + 2)*(x + 3))`

`expand` also uses mathematical identities between the functions:

`expand(sin(5*x))`

`expand` works recursively for all subexpressions:

`expand((sin(3*x) + 1)*(cos(2*x) - 1))`

To prevent the expansion of particular subexpressions, pass these subexpressions to `expand` as arguments:

`expand((sin(3*x) + 1)*(cos(2*x) - 1), sin(3*x))`

To prevent the expansion of all trigonometric subexpressions in this example, use the option `ArithmeticOnly`:

`expand((sin(3*x) + 1)*(cos(2*x) - 1), ArithmeticOnly)`

### Factor Expressions

To present an expression as a product of sums, try the `factor` function. The factored form of the following polynomial is visibly shorter than the original one. The factored form also shows that this polynomial has only one root `x = -5`:

```factor(x^10 + 50*x^9 + 1125*x^8 + 15000*x^7 + 131250*x^6 + 787500*x^5 + 3281250*x^4 + 9375000*x^3 + 17578125*x^2 + 19531250*x + 9765625)```

For sums of rational expressions, `factor` first computes a common denominator, and then factors both the numerator and denominator:

```f := (x^3 + 3*y^2)/(x^2 - y^2) + 3: f = factor(f)```

The function also can factor expressions other than polynomials and rational functions. Internally, MuPAD converts such expressions into polynomials or rational function by substituting subexpressions with identifiers. After factoring the expression with temporary identifiers, MuPAD restores the original subexpressions:

`factor((ln(x)^2 - 1)/(cos(x)^2 - sin(x)^2))`

By default, `factor` searches for polynomial factors with rational numbers. The function does not factor the expression into a product containing :

`factor(x^2 - 2)`

To add the constant to the numbers used in factoring, use the option `Adjoin`:

`factor(x^2 - 2, Adjoin = [sqrt(2)])`

### Compute Normal Forms of Expressions

The `normal` function represents the original rational expression as a single rational term with expanded numerator and denominator. The greatest common divisor of the numerator and denominator of the returned expression is 1:

```f := (x^3 + 3*y^2)/(x^2 - y^2) + 3: f = normal(f)```

`normal` cancels common factors that appear in numerator and denominator:

```f := x^2/(x + y) - y^2/(x + y): f = normal(f)```

The `normal` function also handles expressions other than polynomials and rational functions. Internally, MuPAD converts such expressions into polynomials or rational functions by substituting subexpressions with identifiers. After normalizing the expression with temporary identifiers, MuPAD restores the original subexpressions:

```f := (exp(2*x) - exp(2*y))/(exp(3*x) - exp(3*y)): f = normal(f)```

### Compute Partial Fraction Decompositions of Expressions

The `partfrac` function returns a rational expression in the form of a sum of a polynomial and rational terms. In each rational term, the degree of the numerator is smaller than the degree of the denominator. For some expressions, `partfrac` returns visibly simpler forms, for example:

```partfrac((x^6 + 15*x^5 + 94*x^4 + 316*x^3 + 599*x^2 + 602*x + 247)/(x^6 + 14*x^5 + 80*x^4 + 238*x^3 + 387*x^2 + 324*x + 108), x)```

The denominators in rational terms represent the factored common denominator of the original expression:

`factor(x^6 + 14*x^5 + 80*x^4 + 238*x^3 + 387*x^2 + 324*x + 108)`

### Simplify Radicals in Arithmetic Expressions

As an alternative to the general simplifiers `simplify` and `Simplify`, use the `radsimp` function to simplify arithmetic expressions involving square roots or other radicals. For example, simplify the following numeric expression:

```f := 3*sqrt(7)/(sqrt(7) - 2); radsimp(f)```

### Extract Real and Imaginary Parts of Complex Expressions

When working with complex numbers, you might need to separate the real and imaginary part of a symbolic expression. To extract the real and imaginary part of a complex number, you use the `Re` and `Im` functions. For symbolic expressions, these functions return:

`Re(tan(x)), Im(tan(x))`

Use the `rectform` function to split a symbolic expression into its real and imaginary parts:

`y := rectform(tan(x))`

To extract the real and imaginary parts of `y`, use the `Re` and `Im` functions:

`Re(y); Im(y)`

### Rewrite Expressions in Terms of Other Functions

To present an expression in terms of a particular function, use the `rewrite` command. The command uses mathematical identities between functions. For example, rewrite an expression containing trigonometric functions in terms of a particular trigonometric function:

```sin(x) = rewrite(sin(x), tan); cos(x) = rewrite(cos(x), tan); sin(2*x) + cos(3*x)^2 = rewrite(sin(2*x) + cos(3*x)^2, tan)```

Use `rewrite` to express the trigonometric and hyperbolic functions in terms of the exponential function:

```sin(x) = rewrite(sin(x), exp); cos(x) = rewrite(cos(x), exp); sinh(x) = rewrite(sinh(x), exp); cosh(x) = rewrite(cosh(x), exp)```

The command also expresses inverse hyperbolic functions in terms of logarithms:

```arcsinh(x) = rewrite(arcsinh(x), ln); arccosh(x) = rewrite(arccosh(x), ln)```

As target functions, `rewrite` accepts: direct and inverse trigonometric functions, direct and inverse hyperbolic functions, `diff`, `D`, `erf`, `exp`, `fact`, `gamma`, `harmonic`, `piecewise`, and more. See the `rewrite` help page for the complete list of target functions.

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos