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 evaluate $$\displaystyle J=A\sum_{k=0}^{n-2}(-1)^k{n-2 \choose k}B^{n-2-k}\left(\frac{C_1}{k+n}-\frac{C_2}{k+n+1}+\frac{C_3}{k+n+2}-\frac{2}{k+n+3}\right)$$ in Mathematica as a function of n (i.e. J[n])

Note that B, C1, C2, etc are just coefficients for some parameters I have in the model. I assign their values before I enter the function. They are given below for reference

$$\left\{\begin{array}{cc}\left((n-1)nv^{-2n}\lambda^{-n}\right)=A \\ v+\lambda v=B\end{array}\right.$$ $$\left\{\begin{array}{cc}(v^2B\lambda)=C_1 \\ (vB+(B+2v)\lambda v)=C_2 \\ (2\lambda v+B+2v)=C_3 \end{array}\right.$$

Currently I have J[n] coded as:

J[n_] := 
  a Sum[(-1^k) Binomial[n - 2, k] (b^(n - 2 - k)) 
      ((c1/(k + n)) - (c2/(k + n + 1)) - (c3/(k + n + 2)) - (2/(k + n + 3))), 
    {k, 0, n - 2}]

But when I call it by J[5] with {v, lambda} = {1.3, 2.1}, for instance, I get a negative value when it should be positive!

Another user, Dolma, who helped me derive the function (it's a definite integral of another function) claims it is positive here.

I trust that I am doing something wrong more so than Dolma's derivation being wrong, though I should mention Mathematica provides a MUCH more complex answer to this integral than in the post above.

Can anyone spot where I am making a mistake?

I appreciate your time and insight!

share|improve this question

closed as too localized by Sjoerd C. de Vries, m_goldberg, Yves Klett, Artes, halirutan Apr 24 '13 at 10:07

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

I should add that I'm new to both stack exchange and somewhat new to Mathematica (only a user since v7), so I apologize for anything glaring I have missed. – BorderedHessian Apr 24 '13 at 4:04
It would be useful to see all of the code. Note that there is a difference between (-1)^k and -1^k. – Jonathan Shock Apr 24 '13 at 4:38
I tried both the initial integral and the series you give for your provided values and get the same result $0.31644$ if you get $-0.31644$ the I think that @JonathanShock hit the spot. – Spawn1701D Apr 24 '13 at 4:44
EDIT- Thanks @JonathanShock Shock, this worked, I GREATLY appreciate it. I've been staring at the damn thing for too long. – BorderedHessian Apr 24 '13 at 4:47
..and in your Mathematica input, your third term in the Binomial is '-(c3/(k+n+2))' whereas in your formula its '+(c3....)' – PlaysDice Nov 19 '13 at 14:28
up vote 5 down vote accepted

Note that in Mathematica there is a difference between (-1)^k and -1^k

This should solve the problem in this case.

share|improve this answer
I don't know if it's the done thing to write up an answer when a comment has solved the problem but I presume it's best to do so in order to show that it has been solved. – Jonathan Shock Apr 24 '13 at 5:20
Followup- How often do you think people look over this distinction? I had no idea. – BorderedHessian Apr 24 '13 at 5:26
@BorderedHessian, can't help you there I'm afraid. If you want to know what's happening with a particular syntax then looking at the FullForm of the expression can be of use. – Jonathan Shock Apr 24 '13 at 6:18

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