1
$\begingroup$

I want to write a sum over "i" whose limits are like "i" starting 1 to 10 but "i" not equal to 2. How to write this?

$\endgroup$
2
  • 5
    $\begingroup$ I see at least three ways to do it: Sum[If[i == 2, 0, f[i]], {i, 1, 10}] or Sum[Piecewise[{i == 2, 0}, {i != 2, f[i]}], {i, 1, 10}] or just sum from 3 to 10 and add the one: Sum[f[i],{i,3,10}] + f[1] $\endgroup$
    – flinty
    Jul 13 '20 at 13:02
  • 3
    $\begingroup$ Total[f /@ Delete[Range[10], 2]] $\endgroup$ Jul 13 '20 at 13:25
3
$\begingroup$
f /@ Cases[Except[2]]@Range[10] // Total


Sum[f[i]*Boole[i != 2], {i,10}]
$\endgroup$
2
$\begingroup$
Sum[m+17, {m, Range[10] /. 2 -> Nothing}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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