# Define a variable whose value for each i in [|1,n|] depends on the average value it takes for j different from i [closed]

I would like to define the following variable :

So the average value (a) takes for every "individual" but i.

But actually, for each i, the value (a) takes depends on the preceding average:

Finally, I would like to compute the following sum :

I don't have a very large culture in Wolfram, but I have tried all I could without succeeding. Could someone help me please ? I hope my request is clear enough.

Best,

Peter

• What are $f$ and $g$? You might have to solve a system of nonlinear equations in order to obtain the $a_i$ and $\hat a_{-i}$. And that will be impossible without known at leas $g$. – Henrik Schumacher Aug 31 '18 at 15:30
• Tanks for your answer. I know both $f$ and $g$ but they but as they are quite complex I though it was not necassary to put their explicit expression. Here they are : – Peter Aug 31 '18 at 17:27
• $\frac{\big(-3A^{2}+2A^{2}\hat{a}_{-i}+16w_{0}^{2}(A+1-2\hat{a}_{-i})\big)+\theta_{i}\big((8\hat{a}_{-i}-12-32w_{0}^{2})A+(6-4\hat{a}_{-i}-8x\hat{a}_{-i})A^{2}+x\big((12-16\hat{a}_{-i}+32w_{0}^{2})A+(8\hat{a}_{-i}-6)\big)}{\big(32A+2A^{2}-32-160w_{0}^{2})+\theta_{i}\big(16A-A^{2}(-8-16x)\big)+x\big(-16A-8A^{2}\big)}$ = $a_{i}$ – Peter Aug 31 '18 at 17:39
• Then I would want to compute : $\bigg(\sum_{i=1}^{n}w_{0}\big(\frac{1}{2}+R_{i}(a_{i};e_{i})\big)^{2}\bigg)$ with $R_{i}(a_{i};e_{i})=\frac{\phi(a_{i}-\hat{a}_{-i})+\beta e_{i}}{1-p}$ – Peter Aug 31 '18 at 17:43
• Peter, it would help if you add these formulas in Mathematica syntax to your question. (You find a link called "edit" right below your question. Moreover, many new undeclared symbols popped up in your new formula. Please, get into the habit to give complete information. If you don't do your part, why should anyone bother to figure out what you mean? – Henrik Schumacher Aug 31 '18 at 17:49

To define $\hat{a}_i$ you can use:

ahat1[lst_, i_] := Mean[Drop[lst, {i}]]

lst = Array[Subscript[a, #] &, 10];
ahat1[lst, 4]


$\frac{1}{9} \left(a_1+a_2+a_3+a_5+a_6+a_7+a_8+a_9+a_{10}\right)$

Faster alternatives:

ahat2[lst_, i_] := With[{l = Length[lst] - 1},  Subtract[Total[lst], lst[[i]]]/ l]
ahat3[lst_, i_] := With[{l = Length[lst] - 1}, (1 + 1/l) Mean[lst] - lst[[i]]/l]


Timings:

ll = RandomInteger[10000, 1000000];
ahat1[ll, 3] // RepeatedTiming


{0.0030, 4996512583/999999}

ahat2[ll, 3] // RepeatedTiming


{0.00164, 4996512583/999999}

ahat3[ll, 3] // RepeatedTiming


{0.00163, 4996512583/999999}

• Thanks a lot for this answer, it will help me a lot ! I will use the "ahat2 way". – Peter Aug 31 '18 at 17:51