Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

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

Search the Archive

If and Piecewise don't quite do what I need

  • To: mathgroup at
  • Subject: [mg113398] If and Piecewise don't quite do what I need
  • From: Sam Takoy <sam.takoy at>
  • Date: Wed, 27 Oct 2010 05:15:18 -0400 (EDT)


I have found that If doesn't do winside it like I would want it to do. 
Piecewise does do it, but then it doesn't work the way I would want it. 
Is there a solution that does both?


c[n_] := Piecewise[{{1, {n, 0}}},
   Integrate[a^2 Cos[n a], {a, -Pi, Pi}]]
c[n] (* Calculates the Integral *)
Sum[c[n], {n, 0, Infinity}] (* But fails to Sum *)
d[n_] := If[n == 0, 1, Integrate[a^2 Cos[n a], {a, -Pi, Pi}]] (* Fails 
to calculate the integral *)
d[n] (* But does sum OK *)
Sum[d[n], {n, 0, Infinity}]

I want it to evaluate the integral and to sum properly.



PS: Slightly offtopic, I found that the Limit trick for n = 0 with 
Fourier coefficients often doesn't work resulting in a 0*Infinity 

  • Prev by Date: Re: how to read Wolfram technology conference 2010 presentations?
  • Next by Date: Re: Minimize - What am I doing worng?
  • Previous by thread: Re: Importing data
  • Next by thread: Re: If and Piecewise don't quite do what I need