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} ]
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}]
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*)