Message Boards Message Boards

5 Replies
5 Total Likes
View groups...
Share this post:

How to transform distinguing odd/even powers?

Posted 10 years ago


A just beginner question:

How can I do this transformation:

Cos[X_]^n -> ( (1+Cos[2*X])/2)^(n/2), if n is even Cos[X_]^n -> Cos[X]( (1+Cos[2X])/2)^((n-1)/2), if n is odd ?

Thanks in advance César Lozada

POSTED BY: Cesar Lozada
5 Replies

Try something like:

Fcos[x_, n_Integer?OddQ]:=  definition odd
Fcos[x_, n_Integer?EvenQ]:=  definition even
POSTED BY: Sander Huisman
Posted 10 years ago

Thanks, Frank, Blinder and Todd.

I did:

Fcos[x_, n_] := 
             If[n == 1, Cos[x]^n, 
                If[EvenQ[n], Expand[((1 + Cos[2*x])/2)^(n/2)], 
                   Cos[x]*Expand[((1 + Cos[2*x])/2)^((n - 1)/2)]]]

z = Factor[Expand[Cos[A]^9 //. {Cos[x_]^k_ -> Fcos[x, k]}]]


1/128 Cos[A] (35 + 48 Cos[2 A] + 28 Cos[4 A] + 16 Cos[2 A] Cos[4 A] + Cos[8 A])

If you go back from this expression with Simplify[] you get again Cos[A]^9

Thanks again. Today is my 2nd day with Mathematica.

C├ęsar Lozada

POSTED BY: Cesar Lozada

I think Frank is suggesting using Condition with Rule, see the documentation for examples and don't forget to use "n_"

It might work, but if not, then your expression is being automatically transformed before the rule, you might consider wrapping the expression in Hold before the rule replacement. You can ReleaseHold after the rule replacement.

POSTED BY: Todd Rowland

or use a construction something like

F[x] = Feven[x] * Boole[(-1)^n == 1] + Fodd[x] * Boole[(-1)^n == -1]
POSTED BY: S M Blinder

Do two function or rule definitions, one using EvenQ and the other using OddQ.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract