In[]:=
deploy
Mon 27 Dec 2021 17:09:23

Small n

In[]:=
setupProblem[nn_]:=Clear[x];​​n=nn;​​hs=Table
1
i
,{i,1,n};​​xs=Array[x,n];​​Z=
2
n/2
π
Gamma[n/2]
;(*Z=Integrate[1,xs∈R]*)​​;​​​​normalRatio:=​​dist=MultinormalDistribution[IdentityMatrix[n]];​​TransformedDistribution
2
hs
.
2
xs
3
hs
.
2
xs
,xsdist​​;​​setupProblem[2];​​Mean[normalRatio]
Out[]=
2
7
(3+
2
)

Large n

In[]:=
sampleLR[nn_,samples_]:=​​n=nn;​​hs=Table
1
i
,{i,1,n};​​xs=Array[x,n];​​dist=MultinormalDistribution[IdentityMatrix[n]];​​RandomVariateTransformedDistribution
2
hs
.
2
xs
3
hs
.
2
xs
,xsdist,samples​​;​​data=sampleLR[1000,1000000];​​Mean[data]​​skd=SmoothKernelDistribution[data,Automatic,{"Bounded",{0,10},"Epanechnikov"}];​​img=Plot[PDF[skd,x],{x,0,10},FillingAxis,PlotRangeAll]
Out[]=
1.98912
Out[]=

Dot product representation

In[]:=
solveDot[nn_]:=​​n=nn;​​hs=Table
1
i
,{i,1,n};​​xs=Array[x,n];​​dist=MultinormalDistribution[DiagonalMatrix[
3
hs
]];​​distz=TransformedDistribution
2
xs
Total[
2
xs
]
,xsdist;​​z=NExpectation[xs,xsdistz];​​Total[z*Range[n]]​​;​​solveDot[2]
Out[]=
1.2612
In[]:=
solveDot[3]
Out[]=
1.41505

Animation

In[]:=
exportAnim[fn_,images_,is_]:=Module[{},​​rasters=images;​​SetDirectory[NotebookDirectory[]];​​SetDirectory["export"];​​Export[fn,rasters,"AnimationRepetitions"Infinity]​​];​​​​cylinder[t_]:=With{x=Cos[t],y=Sin[t]},Graphics3D@Cylinder{x,y,0},x,y,
2
x
+1/2
2
y
2
x
+1/4
2
y
,1100;​​plot3da=Plot3D0,
2
x
+12
2
y
,
2
x
+14
2
y
,{x,-1,1},{y,-1,1},MeshFalse,RegionFunctionFunction[{x,y,z},x^2+y^2≤1],MeshFunctions{#3&},BoxedFalse,AxesNone,PlotStyleOpacity[0.5],PlotPoints50;​​plot3d[t_]:=Show[plot3da,cylinder[t]]​​blue=ColorData[97,"ColorList"][[1]];​​(*plot2da=Plot[Callout[
2
Cos[t]
+3
2
Sin[t]
,"
λ
1
",Above],Callout[
2
Cos[t]
+3
2
Sin[t]
,"
λ
2
",Below],Callout[2,"
λ
ave
",Above],{t,0,2Pi},PlotStyle{blue,blue,Dashed},AxesOrigin{0,0}];*)​​plot2da=Plot
2
Cos[t]
+
2
Sin[t]
4
2
Cos[t]
+
2
Sin[t]
8
,Callout[1.261,"1.261",Above],{t,0,2Pi},AxesOrigin{0,0},PlotStyle{Automatic,Dashed},PlotRangePadding.75,Ticks{{Pi/2,Pi,3Pi/2,2Pi},{0,1,1.5,2}},PlotRangeAll;​​point[t_]:=ListPlotWith{x=Cos[t],y=Sin[t]},t,
2
Cos[t]
+
2
Sin[t]
4
2
Cos[t]
+
2
Sin[t]
8
,PlotStylePointSize[Large],FillingAxis,FillingStyleDirective[Orange,Opacity[0.8]]​​plot2d[t_]:=Show[plot2da,point[t],ImageSize400];​​plotCombined[t_]:=GraphicsRow[{Show[plot3d[t],ImageSize600],Show[plot2d[t],ImageSize500]}]​​plotCombined[2]
Out[]=

Distribution plots

Two dimensions explicit