3
$\begingroup$

How can I add this condition

Ei[i] + Ei[j] != 0

to the following summation?

Sum[ (2 Ei[i] Ei[j])/(Ei[i] + Ei[j]), {j, 1, 4}, {i, 1, 4} ]
$\endgroup$

1 Answer 1

5
$\begingroup$

One way might be to add an If inside the Sum

Ei[1] = 1; Ei[2] = 2; Ei[3] = -1; Ei[4] = 5;
Sum[(2 Ei[i] Ei[j])/(Ei[i] + Ei[j]), {j, 1, 4}, {i, 1, 4}]

enter image description here

Replace with

Sum[den = (Ei[i] + Ei[j]); 
 If[den != 0, (2 Ei[i] Ei[j])/den, 0], {j, 1, 4}, {i, 1, 4}]

(*40/7*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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