|
| 1 | +#randomgrowth2.jl |
| 2 | +using Winston |
| 3 | +using ODE |
| 4 | +include("../1/gradient.jl") |
| 5 | + |
| 6 | +function randomgrowth2() |
| 7 | + num_trials = 2000 |
| 8 | + g = 1 |
| 9 | + q = 0.7 |
| 10 | + Ns = 80 # [50, 100, 200] |
| 11 | + # [-1.771086807411 08131947928329] |
| 12 | + # Gap = c d^N |
| 13 | + for jj = 1:length(Ns) |
| 14 | + N = Ns[jj] |
| 15 | + M = round(N*g) |
| 16 | + B = zeros(num_trials) |
| 17 | + @time begin |
| 18 | + for ii = 1:num_trials |
| 19 | + # G = G[M, N, q] |
| 20 | + # B[ii] = G[M,N] |
| 21 | + B[ii] = G(M, N, q) |
| 22 | + end |
| 23 | + end |
| 24 | + C = (B - N*om(g,q)) / (sigma_growth(g,q)*N^(1/3)) |
| 25 | + d = 0.2 |
| 26 | + x, n = hist(C - exp(-N*0.0025 - 3), -6:d:4) |
| 27 | + p = FramedPlot() |
| 28 | + h = Histogram(n/(d*num_trials), step(x)) |
| 29 | + h.x0 = first(x) |
| 30 | + add(p, h) |
| 31 | + |
| 32 | + ## Theory |
| 33 | + t0 = 4 |
| 34 | + tn = -6 |
| 35 | + dx = 0.005 |
| 36 | + deq = (t, y) -> [y[2]; t*y[1]+2*y[1]^3; y[4]; y[1]^2] |
| 37 | + y0 = [airy(t0); airy(1,t0); 0; airy(t0)^2] # boundary conditions |
| 38 | + t, y = ode23(deq, t0:-dx:tn, y0) # solve |
| 39 | + F2 = exp(-y[:,3]) # the distribution |
| 40 | + f2 = gradient(F2, t) # the density |
| 41 | + |
| 42 | + add(p, Curve(t, f2, "color", "red", "linewidth", 3)) |
| 43 | + Winston.display(p) |
| 44 | + println(mean(C)) |
| 45 | + end |
| 46 | +end |
| 47 | + |
| 48 | +function G(N, M, q) |
| 49 | + # computes matrix G[N,M] for a given q |
| 50 | + GG = floor(log(rand(N,M))/log(q)) |
| 51 | + #float(rand(N,M) < q) |
| 52 | + |
| 53 | + # Compute the edges: the boundary |
| 54 | + for ii = 2:N |
| 55 | + GG[ii, 1] = GG[ii, 1] + GG[ii-1, 1] |
| 56 | + GG[1, ii] = GG[1, ii] + GG[1, ii-1] |
| 57 | + end |
| 58 | + # Compute the inside |
| 59 | + for ii = 2:N |
| 60 | + for jj = 2:M |
| 61 | + GG[ii, jj] = GG[ii, jj] + max(GG[ii, jj-1], GG[ii-1, jj]) |
| 62 | + end |
| 63 | + end |
| 64 | + ## Plot |
| 65 | + # imagesc((0,N),(M,0),GG) |
| 66 | + # sleep(.01) |
| 67 | + |
| 68 | + return GG[N, M] |
| 69 | +end |
| 70 | + |
| 71 | +# helper functions sigma.m and om, which describe mean and |
| 72 | +# standard deviation of G[N, M] |
| 73 | + |
| 74 | +# Computes G[qN,N]/N for N->inf |
| 75 | +om(g,q) = ((1 + sqrt(g * q)) ^ 2) / (1 - q) - 1 |
| 76 | + |
| 77 | +sigma_growth(r, q) = |
| 78 | + q^(1/6) * r^(1/6) / (1 - q) * |
| 79 | + (sqrt(r) + sqrt(q))^(2/3) * |
| 80 | + (1 + sqrt(q * r))^(2/3) |
| 81 | + |
| 82 | + |
| 83 | +randomgrowth2() |
0 commit comments