Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a function which will perform the equation in the attached image. So far, I have:

x[n_] :=
 x[n] =
  2^(1 - n) Sum[Binomial[n, k] T[n - 2 k], {k, 0, n/2}]

x[6]

which outputs:

$ \frac{1}{32} (20 T(0)+15 T(2)+6 T(4)+T(6)) $

How can I write an If[] (or similar) statement to half the kth term when n is even and k=n/2? Thanks in advance!

Equation 2.14

share|improve this question
up vote 2 down vote accepted

You can write it like this:-

x[n_] :=
 x[n] =
  2^(1 - n) Sum[Binomial[n, k] T[n - 2 k]/If[EvenQ[n] && k == n/2, 2, 1],
    {k, 0, n/2}]

x[6]

1/32 (10 T[0] + 15 T[2] + 6 T[4] + T[6])

share|improve this answer

I'd like to suggest a solution that makes use of pattern matching - the (to me) a little awkward phrasing 'if n is even and k=n/2 simply means the following:

In the case of even n (as Floor[n/2] == n/2 if EvenQ[n]==True), run the sum to n-1 (as k==n/2 means 'the last term' in this case) and add the last term (which is 2^(-n) Binomial[n, n/2] T[0] manually.

So:

x[n_] := 2^(1 - n) Sum[Binomial[n, k] T[n - 2 k], {k, 0, n/2}]
x[n_/; EvenQ[n]] := x[n-1] + 2^(-n) Binomial[n,n/2] T[0]
share|improve this answer

I think an elegant way is using PieceWise:

x[n_] := 2^(1 - n) Sum[
   Piecewise[{{1/2, EvenQ[n] && k == n/2}, {1, True}}] Binomial[n, k] T[n - 2 k], {k, 0, n/2}]

so the first six terms are:

x /@ Range[6]

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.