# Function giving negative value when it should be positive [closed]

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!

-

## closed as too localized by Sjoerd C. de Vries, m_goldberg, Yves Klett, Artes, halirutanApr 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

Note that in Mathematica there is a difference between (-1)^k and -1^k
@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