1
$\begingroup$

This question already has an answer here:

I have the following term which I would like to express correctly in Mathematica:

$$\sum_{i=1}^{m}\frac{1}{\prod_{j=1,j\neq i}^m(\rho_i-\rho_j)}$$

This means that for $m=3$ for example you should get the following

$$ \frac{1}{(\rho_1-\rho_2)(\rho_1-\rho_3)}+\frac{1}{(\rho_2-\rho_1)(\rho_2-\rho_3)}+\frac{1}{(\rho_3-\rho_2)(\rho_3-\rho_1)} $$

Can you please help?

$\endgroup$

marked as duplicate by Roman, m_goldberg, corey979, user64494, MarcoB Jun 5 at 14:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ There is no duplication since the other question does not have a sum and thus the $i$ is not well defined. I chose to put a new question instead of creating some confusion. $\endgroup$ – Y.L Jun 5 at 14:44
1
$\begingroup$
f[m_Integer] := Sum[1/Product[(Subscript[\[Rho], i] - Subscript[\[Rho], j]),
    {j, Complement[Range[1, m], {i}]}], {i, m}]

f[3]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks @Chris Degnen this is easy to implement into my calculations. $\endgroup$ – Y.L Jun 5 at 15:28
2
$\begingroup$
With[{m = 3},
  Sum[1/Product[ρ[i] - ρ[j], {j, DeleteCases[Range[m], i]}], {i, m}]]

$$ \frac{1}{(\rho (2)-\rho (1)) (\rho (2)-\rho (3))}+\frac{1}{(\rho (3)-\rho (1)) (\rho (3)-\rho (2))}+\frac{1}{(\rho (1)-\rho (2)) (\rho (1)-\rho (3))} $$

Here I used ρ[i] instead of Subscript[ρ,i] because subscripts are a pitfall for new users.

Update: It's easier to use Drop instead of DeleteCases, as in @kglr's solution:

With[{m = 3}, 
  Sum[1/Product[ρ[i] - ρ[j], {j, Drop[Range[m], {i}]}], {i, m}]]
$\endgroup$
0
$\begingroup$
ClearAll[f1, f2]
f1[m_] := Module[{a = Array[ρ, m]}, m / 
  HarmonicMean @ MapIndexed[Apply[Times] @* Drop, Outer[Subtract, a, a]]

f2[m_] := Module[{a = Array[ρ, m]}, 
  m Moment[ MapIndexed[Apply[Times] @* Drop, Outer[Subtract, a, a], -1]]


f1[3]  

enter image description here

f1[4] 

enter image description here

And @@ (f1[#] == f2[#] & /@ Range[100])

True

$\endgroup$

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