How to interpret or calculate this sum?

61 Views Asked by At

I am trying to solve the following mathematical equation:

$4[8\sum q_1(1 - q_1).q_2(1-q_2)]$

$q_1$ = is a vector of length $10000$, with values between $0-1$ $q_2$ = is a vector of length $10000$, with values between $0-1$

My question is how the order of the calculations should be, I have two exclusive possibilities in mind:

1) solve first $q_1(1 - q_1)$ times $q_2(1-q_2)$, and then make the summation of this values, and finally multiply by $8$ and $4$.

2) make first separately the summation of $q_1(1 - q_1)$ and the summation of $q_2(1 - q_2)$, and then multiply each other, and finally multiply by 8 and by 4

The results are different so I am not sure which is the correct one.

Thank you.

1

There are 1 best solutions below

1
On BEST ANSWER

I am trying to solve the following mathematical equation:

$4[8\sum q_1(1 - q_1).q_2(1-q_2)]$

In order to compute this, you need the values over which to sum these terms. So let's write $q_{1,k}$ for the $k$-th entry of $q_1$ ans similar for $q_2$. Presumably, the sum extends over all of the 10000 elements, and depending on programming language, the array index extends run from 0 to 9999 or from 1 to 10000. Let's assume C convention (0 to 9999), then your term denotes as:

$$ 4\Big(8\sum_{k=0}^{9999} q_{1,k}·(1 - q_{1,k})\cdot q_{2,k}·(1-q_{2,k})\Big) $$ which is $$32\Big( q_{1,0}·(1 - q_{1,0})\cdot q_{2,0}·(1-q_{2,0}) +\cdots+ q_{1,9999}·(1 - q_{1,9999})\cdot q_{2,9999}·(1-q_{2,9999}) \Big) $$ Denoted in some pseudo language:

sum ← 0
for k from 0 to 9999
    sum ← sum + q1[k] * (1 - q1[k]) * q2[k] * (1 - q2[k])
result ← 4 * 8 * sum

There are also languages like R that can efficiently and conveniently handle vectors and such (and are wide spread in biology), hence with such a language you don't want to operate entry-by-entry by hand.