Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# subexpr

Rewrite symbolic expression in terms of common subexpressions

## Syntax

[Y,SIGMA] = subexpr(X,SIGMA)
[Y,SIGMA] = subexpr(X,'SIGMA')

## Description

[Y,SIGMA] = subexpr(X,SIGMA) or [Y,SIGMA] = subexpr(X,'SIGMA') rewrites the symbolic expression X in terms of its common subexpressions.

## Examples

The statements

```h = solve('a*x^3+b*x^2+c*x+d = 0');
[r,s] = subexpr(h,'s')```

return the rewritten expression for t in r in terms of a common subexpression, which is returned in s:

```r =
s^(1/3) - b/(3*a) - (- b^2/(9*a^2) + c/(3*a))/s^(1/3)
(- b^2/(9*a^2) + c/(3*a))/(2*s^(1/3)) - s^(1/3)/2 +...
(3^(1/2)*(s^(1/3) + (- b^2/(9*a^2) + c/(3*a))/s^(1/3))*i)/2 - b/(3*a)
(- b^2/(9*a^2) + c/(3*a))/(2*s^(1/3)) - s^(1/3)/2 -...
(3^(1/2)*(s^(1/3) + (- b^2/(9*a^2) + c/(3*a))/s^(1/3))*i)/2 - b/(3*a)

s =
((d/(2*a) + b^3/(27*a^3) - (b*c)/(6*a^2))^2 +...
(- b^2/(9*a^2) + c/(3*a))^3)^(1/2) - b^3/(27*a^3) -...
d/(2*a) + (b*c)/(6*a^2)
```