Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# rewrite

Rewrite expression in new terms

## Syntax

rewrite(expr,target)
rewrite(A,target)

## Description

rewrite(expr,target) rewrites the symbolic expression expr in terms of target. The returned expression is mathematically equivalent to the original expression.

rewrite(A,target) rewrites each element of A in terms of target.

## Input Arguments

 expr Symbolic expression. A Vector or matrix of symbolic expressions. target One of these strings: exp, log, sincos, sin, cos, tan, sqrt, or heaviside.

## Examples

Rewrite these trigonometric functions in terms of the exponential function:

```syms x
rewrite(sin(x), 'exp')
rewrite(cos(x), 'exp')
rewrite(tan(x), 'exp')```
```ans =
(exp(-x*i)*i)/2 - (exp(x*i)*i)/2

ans =
exp(-x*i)/2 + exp(x*i)/2

ans =
-(exp(x*2*i)*i - i)/(exp(x*2*i) + 1)```

Rewrite the tangent function in terms of the sine function:

```syms x
rewrite(tan(x), 'sin')```
```ans =
-sin(x)/(2*sin(x/2)^2 - 1)```

Rewrite the hyperbolic tangent function in terms of the sine function:

```syms x
rewrite(tanh(x), 'sin')```
```ans =
(sin(x*i)*i)/(2*sin((x*i)/2)^2 - 1)```

Rewrite these inverse trigonometric functions in terms of the natural logarithm:

```syms x
rewrite(acos(x), 'log')
rewrite(acot(x), 'log')```
```ans =
-log(x + (1 - x^2)^(1/2)*i)*i

ans =
(log(1 - i/x)*i)/2 - (log(i/x + 1)*i)/2```

Rewrite the rectangular pulse function in terms of the Heaviside step function:

```syms a b x
rewrite(rectangularPulse(a, b, x), 'heaviside')```
```ans =
heaviside(x - a) - heaviside(x - b)```

Rewrite the triangular pulse function in terms of the Heaviside step function:

```syms a b c x
rewrite(triangularPulse(a, b, c, x), 'heaviside')```
```ans =
(heaviside(x - a)*(a - x))/(a - b) - (heaviside(x - b)*(a - x))/(a - b) - (heaviside(x - b)*(c - x))/(b - c) + (heaviside(x - c)*(c - x))/(b - c)```

Call rewrite to rewrite each element of this matrix of symbolic expressions in terms of the exponential function:

```syms x
A = [sin(x) cos(x); sinh(x) cosh(x)];
rewrite(A, 'exp')```
```ans =
[ (exp(-x*i)*i)/2 - (exp(x*i)*i)/2, exp(-x*i)/2 + exp(x*i)/2]
[             exp(x)/2 - exp(-x)/2,     exp(-x)/2 + exp(x)/2]```

Rewrite the cosine function in terms of sine function. Here rewrite replaces the cosine function using the identity cos(2*x) = 1 – sin(x)^2 which is valid for any x:

```syms x
rewrite(cos(x),'sin')```
```ans =
1 - 2*sin(x/2)^2```

rewrite does not replace the sine function with either or because these expressions are only valid for x within particular intervals:

```syms x
rewrite(sin(x),'cos')```
```ans =
sin(x)```