MATLAB: Sin(x)^2

MATLAB

How to expand a function like sin(x)^2 to output 1/2*(1-cos(2*x))? I tried expand(sin(x)^2) but it returns the same.

Best Answer

Use the rewrite function:
syms x
ys = sin(x)^2;
ye = rewrite(ys, 'exp')
yc = rewrite(expand(ye), 'cos')
p[roducing:
yc =
1/2 - cos(2*x)/2