In[]:=
deploy
Fri 25 Jun 2021 09:03:30
https://stats.stackexchange.com/questions/532117/distribution-of-langle-x2-a-rangle-where-x-is-is-a-random-direction
In[]:=
With[{n=7},​​avec=Array[a,n];​​xvec=Array[x,n-1];​​xvec2=xvec~Join~{1-Total[xvec]};​​dist=DirichletDistribution[ConstantArray[1/2,n]];​​{Expectation[avec.xvec2,xvecdist],Expectation[
2
(avec.xvec2)
,xvecdist]}//FullSimplify​​]
Out[]=

1
7
(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]),
1
63
(3
2
a[1]
+3
2
a[2]
+3
2
a[3]
+2a[3]a[4]+3
2
a[4]
+2a[3]a[5]+2a[4]a[5]+3
2
a[5]
+2a[3]a[6]+2a[4]a[6]+2a[5]a[6]+3
2
a[6]
+2(a[3]+a[4]+a[5]+a[6])a[7]+3
2
a[7]
+2a[2](a[3]+a[4]+a[5]+a[6]+a[7])+2a[1](a[2]+a[3]+a[4]+a[5]+a[6]+a[7]))
In[]:=
stddev[n_]:=Module[{},​​avec=Table[1/i,{i,1,n}];​​xvec=Array[x,n-1];​​xvec2=xvec~Join~{1-Total[xvec]};​​dist=DirichletDistribution[ConstantArray[1/2,n]];​​Sqrt[Expectation[
2
(avec.xvec2)
,xvecdist]]//N​​];​​gendata[f_,max_,n_]:=TableWithx=Floor
i
n
(max)
,{x,f[x]},{i,1,n};​​gendata[f_,max_,n_]:=TableWithx=Floor
i
n
(max)
,{x,f[x]},{i,0,n};​​max=60;​​ShowLogLogPlot
1
Sqrt[x]
,{x,1,max},PlotLegends"sqrt[x]",ListLogLogPlot[gendata[stddev,max,10]],PlotLabel"variance shrinks faster than Law of Large Numbers"
Out[]=
sqrt[x]

Graphical Version

cylinder[t_]:=With{x=Cos[t],y=Sin[t]},Graphics3D@Cylinder{{x,y,0},{x,y,
2
x
+3
2
y
}},1100;​​plot3da=Plot3D[{0,
2
x
+3
2
y
},{x,-1,1},{y,-1,1},RegionFunctionFunction[{x,y,z},x^2+y^2≤1],MeshFunctions{#3&},BoxedFalse,AxesNone,PlotStyleOpacity[0.5]];​​plot3d[t_]:=Show[plot3da,cylinder[t]]​​​​plot2da=Plot[With[{x=Cos[t],y=Sin[t]},
2
x
+3
2
y
],{t,0,2Pi}];​​point[t_]:=ListPlot[With[{x=Cos[t],y=Sin[t]},{{t,
2
x
+3
2
y
}}],FillingAxis]​​plot2d[t_]:=Show[plot2da,point[t],ImageSize300];​​plotCombined[t_]:=GraphicsRow[{plot3d[t],plot2d[t]},ImageSize600,Spacings0];​​plots=Table[plotCombined[t],{t,0,2Pi,2Pi/20}];​​plots//First
Export["quadratic_form.gif",ListAnimate[plots],"AnimationRepetitions"Infinity]