How to find the sum for indices satisfying certain conditions?

Hi all, I have the following question.

Assume that we have integer-valued N >=1 objects such that E_1,…,E_N. Each E_i takes a number between 1 and N, allowing for duplicates.

Let f be a function and X_1,…,X_N be N real numbers.

I want to calculate, for i<j, Σ_{i,j:Ei≠Ej} f(X_E_i)×f(X_E_j)

Any ideas?

Hi @Shoutu

I’m unsure if this is homework or if you are a complete beginner…

In any case, here is something to get you started:

n = 10
e = rand(1:n, n)
@show e

should help you with E and reading the documentation you should be able to construct X. For the main part you need to fill in the ??? parts of

f(e, x, k) = ???
@show sum(??? for j in 1:n for i in 1:j-1)

then. HTH

Thanks a lot goerch!

Please show us what you have tried after reading the documentation as @goerch suggested, and people here can help you if you get stuck at some point.

1 Like