Hello.
A just beginner question:
How can I do this transformation:
Cos[X_]^n → ( (1+Cos[2X])/2)^(n/2), if n is even
Cos[X_]^n → Cos[X]( (1+Cos[2*X])/2)^((n-1)/2), if n is odd ?
Thanks in advance
César Lozada
Hello.
A just beginner question:
How can I do this transformation:
Cos[X_]^n → ( (1+Cos[2X])/2)^(n/2), if n is even
Cos[X_]^n → Cos[X]( (1+Cos[2*X])/2)^((n-1)/2), if n is odd ?
Thanks in advance
César Lozada
Do two function or rule definitions, one using EvenQ and the other using OddQ.
or use a construction something like
F[x] = Feven[x] * Boole[(-1)^n == 1] + Fodd[x] * Boole[(-1)^n == -1]
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.
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]}]]
giving
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
Try something like:
Fcos[x_, n_Integer?OddQ]:= definition odd
Fcos[x_, n_Integer?EvenQ]:= definition even