Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Expanding powers of cosine

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84239] Re: Expanding powers of cosine
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Fri, 14 Dec 2007 23:17:55 -0500 (EST)
  • References: <fjq18t$nl2$1@smc.vnet.net>

michael.p.croucher at googlemail.com wrote:
> Hi
> 
> I would like to express even powers of Cos[x] in terms of powers of
> Sin[x] using the identity Sin[x]^2+Cos[x]^2 = 1.  For example
> 
> Cos[x]^4 = 1 - 2 Sin[x]^2 + Sin[x]^4
> 
> I could not get any of Mathematica's built in functions to do this for
> me so I created my own rule:
> 
> expandCosn[z_] := Module[{s, res},
>   s = Cos[x]^n_ :> (1 - Sin[x]^2) Cos[x]^(n - 2) ;
>   res = z //. s;
>   Expand[res]
>   ]
> 
> which works fine:
> 
> In[14]:= expandCosn[Cos[x]^4]
> 
> Out[14]= 1 - 2 Sin[x]^2 + Sin[x]^4
> 
> My question is - have I missed something?  Is there an easier way to
> do this?
> 
> Cheers,
> Mike
> 
I would add a condition /;(IntegerQ[n]&&n>1) to the delayed rule, just 
to make it a little more robust (you could get an infinite recursion 
with Cos[x]^(3/2), for example), but otherwise your code looks fine - 
simpler than some of the alternatives on offer!

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: WorkingPrecision and plotting functions
  • Next by Date: ParametricPlot3d not showing up when I use the manipulate command
  • Previous by thread: Re: Re: Expanding powers of cosine
  • Next by thread: GridBox Question