Let A, B and C each be random real numbers chosen from the uniform interval (0,1) and z=A+B+C.
If z is written in scientific notation, define X as the second digit of z.
Find the probability distribution of X.
Analytic result:
[0.11431, 0.11377, 0.11224, 0.10972, 0.10621, 0.10171, 0.09622, 0.08974, 0.08227, 0.07381]
Sim result:
[0.1143, 0.1138, 0.1122, 0.1097, 0.1062, 0.1017, 0.0962, 0.0898, 0.0823, 0.0738]
A rationale for analytic solution:
if we can get a closed form for p(x) the probability distribution function valid on the range [0,3], and also the integral, we can take a series of definite integrals. Or just use the cumulative pdf.
The first 100 intervals would be widths of 0.01 between 0 and 1. Then next 20 intervals would be on widths of 0.1 between 1 and 3.
Then by adding appropriate groups together, we could get an exact answer.
For example, from the 120 segments, to get p(4) we would add the intervals from segments 4, 14, 24, ..., 94, 104, and 114
Cumulative probability of sum of three variables where each is uniform (0,1)
if z<0 0
if 0<z<1 z^3/6 0<z<1
if 1<z<2 (-3z^3 + 9z^2 - 9z + 3)/6
if 2<z<3 1 - ((3-z)^3)/6
if z>3 1
https://www.desmos.com/calculator/rp6jxum2fa
[0.11431, 0.11377, 0.11224, 0.10972, 0.10621, 0.10171, 0.09622, 0.08974, 0.08227, 0.07381]
-----
def myCumPdf(z):
if z <=0 :
return 0
if 0 < z and z <= 1:
return (z**3)/6
if 1 < z and z <= 2:
return (-2*z**3 + 9*z**2 - 9*z + 3)/6
if 2 < z and z <= 3:
return 1 - ((3-z)**3)/6
if 3 < z:
return 1
return 'asdf'
def rangeCumPdf(lo,hi):
return myCumPdf(hi) - myCumPdf(lo)
z_segments = []
integral_segs = []
histo = [0 for j in range(10)]
for i in range(100):
z_segments.append(i/100)
for i in range(20):
z_segments.append(1+i/10)
z_segments.append(3)
for i,v in enumerate(z_segments):
if i == 0:
continue
integral_segs.append(rangeCumPdf(z_segments[i-1],v))
for i in range(100):
histo[int(str(i)[-1])] += integral_segs[i]
for i in range(100,120):
histo[int(str(i)[-1])] += integral_segs[i]
y = [round(a,5) for a in histo]
print(y)
Edited on March 8, 2025, 4:36 pm
|
Posted by Larry
on 2025-03-07 20:09:01 |