rewrite

Syntax

Description

rewrite(expr,target) rewrites
the symbolic expression expr in terms of the
target function target. The rewritten expression
is mathematically equivalent to the original expression. If expr is
a vector or matrix, rewrite acts element-wise
on expr.

Rewrite Between Sine and Cosine Functions

Rewrite the cosine function in terms of the
sine function. Here, rewrite replaces the cosine
function using the identity cos(2*x) = 1 – 2*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 sin(x) with
either −1−cos2(x) or 1−cos2(x) because these expressions are not valid for all
x. However, using the square of these expressions to
replace sin(x)^2 is valid for all x.
Thus, rewrite replaces
sin(x)^2.