Ex 1: Distribution of distance of two cities if cities distributed uniformly in plane. p HdL = p 2 2 Ixi - xj M + Iyi - yj M Two formulae we use. 1. If z =f(x,y), we can find the pdf of z, pz HzL by marginalizing the joint pdf p(x,y,z) using the convolution formula: pz HzL = Ù dx dy pHx, y, zL = Ù dx Ù dy∆Hz - f Hx, yLL pX HxL pY HyL 2. Change of variables for densities: pz HzL dz = fA HaL da Distribution of difference of two uniform variables in one dimension In[1230]:= Integrate@ DiracDelta@z - Hx - yL * 1 * 1D, 8x, 0, 1<, 8y, 0, 1<D distr1 = Assuming@z > - 1 && z < 1, % FullSimplifyD Integrate@distr1, 8z, - 1, 1<DH* normalized *L Plot@distr1, 8z, - 1, 1<D Out[1230]= - H1 + zL HeavisideTheta@- 1 - zD - H- 1 + zL HeavisideTheta@1 - zD + 2 z HeavisideTheta@- zD Out[1231]= 1 - z + 2 z HeavisideTheta@- zD Out[1232]= 1 1.0 0.8 0.6 Out[1233]= 0.4 0.2 -1.0 -0.5 0.5 1.0 Distribution of SQUARED difference of two uniform variables by change of variable. Due to ambiguity at z=0, change coordinates separately for z>0 and z<0. Pick up multiplicity of 2 in addition to Jacobian determinant 2 Session09.nb 1 In[1234]:= distr2 = Jdistr1 . z ® *2 2 distr2 = AssumingB 1 s N* s s > 0, Simplify@%DF distr2Fct@x_D := If@0 £ x && x £ 1, distr2 . s ® x, 0D Integrate@distr2, 8s, 0, 1<DH* normalized? *L Plot@distr2, 8s, 0, 1<D 1- s +2 s HeavisideThetaB- s F Out[1234]= s 1 Out[1235]= -1 + s Out[1237]= 1 3.0 2.5 2.0 Out[1238]= 1.5 1.0 0.5 0.2 0.4 0.6 0.8 1.0 Distribution of sum of squared differences again from convolution In[1239]:= distr3 = Integrate@distr2Fct@sD * distr2Fct@ Α - sD, 8s, 0, 1<D -3 + Π Π-4 Out[1239]= -2 + 4 0 Α1 Α +Α 0<Α<1 - 1 + Α - Α + 2 ArcCscB Α F - 2 ArcTanB - 1 + Α F 1 < Α < 2 True Session09.nb In[1240]:= Out[1240]= Integrate@distr3, 8Α, 0, 2<D Plot@distr3, 8Α, 0, 2<D 1 3.0 2.5 2.0 Out[1241]= 1.5 1.0 0.5 0.5 1.0 Transform to distance coordinates, d = In[1242]:= 1.5 2.0 Α . Define separately for 0 < d < 1 and 1 < d < distr4 = PiecewiseB:9Idistr3@@1, 2, 1DD . Α ® d2 M * 2 d, H0 < d && d £ 1L=, :Idistr3@@1, 3, 1DD . Α ® d2 M * 2 d, J1 < d && d < :0, d < 0 ÈÈ d > 2 d d2 - 4 Out[1242]= 2 N>, 2 > >F d2 + Π 2 d - 2 - d2 + 4 0 < d && d £ 1 - 1 + d2 + 2 ArcCscB d2 F - 2 ArcTanB 0 - 1 + d2 F 1 < d && d < True Final result In[1243]:= 2 PlotBdistr4, :d, 0, 2 >, AxesLabel ® 8"d", "pHdL"<F pHdL 1.4 1.2 1.0 0.8 Out[1243]= 0.6 0.4 0.2 0.2 0.4 0.6 0.8 1.0 1.2 Nice, distr. is differentiable in d=1 even though it is not obvious 1.4 d 2 3 4 Session09.nb In[1275]:= deriv = D@distr4, dD Limit@ deriv@@1, 2, 1DD, d -> 1D Limit@ deriv@@1, 4, 1DD, d -> 1D 0 d<0 2d 2d- 4d + 2 d2 - 4 d2 + Π 0<d<1 d2 2 H- 5 + ΠL Out[1275]= d1 2 -2 d 2 d + 1- 1 d d2 2 2 + d2 - 4 2 + d d2 4d - -1+d2 1<d< - - 1 + d2 - 2 ArcCscB d2 F + 2 ArcTanB - 1 + d2 F 0 Indeterminate Out[1276]= 2 H- 5 + ΠL Out[1277]= 2 H- 5 + ΠL d 2 ÈÈ d > True Plot how the first expression becomes negative In[1296]:= distr4@@1, 2, 1DD PlotB:2 d d2 - 4 d2 + Π , 2 d - 2 - d2 + 4 Out[1296]= 2 d - 2 - d2 + 4 - 1 + d2 + 2 ArcCscB d2 F - 2 ArcTanB - 1 + d2 + 2 ArcCscB d2 F - 2 ArcTanB 0.4 1.0 - 1 + d2 F >, :d, 0, - 1 + d2 F 1.0 0.5 Out[1297]= 0.2 2 -1+d2 0.6 0.8 1.2 1.4 -0.5 -1.0 -1.5 distribution of sum of standard uniforms = distribution of difference of shifted uniforms 2 >F 2 Session09.nb In[1256]:= Integrate@ DiracDelta@z - Hx + yL * 1 * 1D, 8x, 0, 1<, 8y, 0, 1<D distr1 = Assuming@z > 0 && z < 2, % FullSimplifyD Integrate@distr1, 8z, - 0, 2<DH* normalized *L Plot@distr1, 8z, 0, 2<D Out[1256]= 2 H- 1 + zL HeavisideTheta@1 - zD - H- 2 + zL HeavisideTheta@2 - zD - z HeavisideTheta@- zD Out[1257]= 2 - z + 2 H- 1 + zL HeavisideTheta@1 - zD Out[1258]= 1 1.0 0.8 0.6 Out[1259]= 0.4 0.2 0.5 1.0 1.5 2.0 5
© Copyright 2026 Paperzz