#OK to post homework #Nick Belov, March 30th 2025, Assignment 18 read "C18.txt": AveLengthSP:=proc(G,a) local D,sm: D:=Dij(G,a): sm := add(D) / G[1]: return evalf(sm): end: #that picks a random weigted graph according to RWG(n,p,K) #M times, finds for each AveLengthSP(G,a) and finds the average and variance for each run. #going to assume a is fixed to be one here AveLengthStat := proc(n,p,K,M) local i, G, x, s1, s2, mu, va: s1 := 0: s2 := 0: for i from 1 to M do G := RWG(n,p,K): x := AveLengthSP(G,1): s1 := s1 + x: s2 := s2 + x^2: od: mu := s1 / M: va := s2 / M - mu^2: return [evalf(mu), evalf(va)] end: #I toned down M to 100 instead of 10000 due to compute limits: #[2.021400000, 0.014482040] #[2.026000000, 0.014350000] #[2.014200000, 0.015542360] #[2.022500000, 0.013534750] #[2.019000000, 0.012619000]