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 that you have read and understand our privacy policy and code of conduct.

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