Some work on 4&5

This commit is contained in:
Milo 2023-07-09 23:13:29 +03:30
parent 52a0a6abb3
commit f69f559ba0
3 changed files with 2091 additions and 91 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,9 @@ First we define an $N \times N$ random matrix. The $i$th element is 1 with proba
In percolation theory, we have a *critical probability*, $p_c$ which is for $p < p_c$ we have no percolation and for $p > p_c$ our system percolates. Our aim is to find the value of $p_c$, but for now we must code the lattice and percolation.
"""
# ╔═╡ 8aa6eaee-9238-4e74-bffc-606f08562ea4
pl₁ = simshow(repeat((sample(1:-1:0, weights([0.75, 1-0.75]), (100,100))), inner = (10, 10)))
# ╔═╡ ea1f7206-eea0-4014-a4fb-3c5f5e78660e
md""" p= $(@bind p NumberField(0.01:0.01:1, default = 0.5))"""
@ -73,20 +76,30 @@ md" Nₜ = $(@bind Nₜ NumberField(50:200))"
# ╔═╡ 47d8f7ec-0d76-4309-9beb-3c288489cb1a
md""" Number of Trials = $(@bind n_trials NumberField(1:200))"""
# ╔═╡ 5d74efcc-4699-4a45-95d5-1029581f84aa
plot(pₛ,(Q./50), label = "Percolation probability")
# ╔═╡ 5e2613e5-5f81-4d24-8e21-708039344754
# ╠═╡ disabled = true
#=
begin
# ╔═╡ 340be4d1-e325-4e8d-b791-e6af5bd2e610
plot(Q[findall(diff(Q) .!= 0)]./50 .+ findlast(Q .== 0))
p_cs = []
# ╔═╡ 1823f63d-e0f0-4867-a762-3ab234717e5f
Qₛᵢ = findall(x -> x != 0 && x != 50, Q)
# ╔═╡ d812351e-5bcc-4de0-a0b0-3bb56f328391
Qₛᵢ[21]
# ╔═╡ 158d3a9c-c435-437e-bf0c-e184ef0e68d1
Qₛ = sum(Q)/length(Q)
for trial in 1:n_trials
lat = sample(1:-1:0, weights([p₁, 1-p₁]), (Nₜ,Nₜ))
pₛ = length(findall(lat .== 0)):-1:1
for i in pₛ
zero_idxs = findall(lat .== 0)
iᵣ = zero_idxs[rand(1:length(zero_idxs))]
lat[iᵣ] = 1
Pₜ = percolation2D(lat)
if isPercolated2D(Pₜ)
Cₚ = count(lat .== 0)/(Nₜ^2)
push!(p_cs,Cₚ)
break
end
end
end
end
╠═╡ =#
# ╔═╡ ffb6129f-303d-4cb4-a8c1-fb5b1e9c1fb9
md"""## Usefull Functions"""
@ -172,21 +185,15 @@ function visualizeV2D(P)
free = RGB(1.0, 1.0, 1.0)
blue = RGB(0.1, 0.2, 0.9)
comm = intersect(P[1, :], P[end, :]) # Common values in top and buttom of P
# Remove 0s and 1s
deleteat!(comm, comm .== 0)
deleteat!(comm, comm .== 1)
m,n = size(P)
pic = zeros(RGB, m, n)
pic[P .> 1] .= blue
pic[P .== 0] .= block
pic[P .> 1] .= free
if isPercolated2D(P)
pic[P .== comm[1]] .= blue
end
pic
pic[P .== 1] .= free
simshow(repeat((pic), inner = (10, 10)))
end
# ╔═╡ 69a26f6f-476d-469b-8ab4-bd1c39cf139d
@ -258,14 +265,6 @@ isPercolated2D(P)
# ╔═╡ 53f6ad3e-2bed-450a-ac8b-afba6ed328ef
visualize2D(P)
# ╔═╡ 3c7cb57d-91b3-4f0a-a0f7-3f202b48fe57
p_cs
# ╔═╡ 86be6a6c-ec68-49c6-a3ce-aa7cce5398c3
if length(p_cs)>0
sum(p_cs)/length(p_cs)
end
# ╔═╡ 3972be44-ac1d-482f-9fe1-69c51c0815c4
begin
pₛ = p₁:ϵ:p₂
@ -288,30 +287,16 @@ begin
end
end
# ╔═╡ 5e2613e5-5f81-4d24-8e21-708039344754
# ╠═╡ disabled = true
#=
begin
# ╔═╡ 5d74efcc-4699-4a45-95d5-1029581f84aa
plot(pₛ,(Q./n_trials), label = "Percolation probability")
p_cs = []
# ╔═╡ 3c7cb57d-91b3-4f0a-a0f7-3f202b48fe57
p_cs
for trial in 1:n_trials
lat = sample(1:-1:0, weights([p₁, 1-p₁]), (Nₜ,Nₜ))
pₛ = length(findall(lat .== 0)):-1:1
for i in pₛ
zero_idxs = findall(lat .== 0)
iᵣ = zero_idxs[rand(1:length(zero_idxs))]
lat[iᵣ] = 1
Pₜ = percolation2D(lat)
if isPercolated2D(Pₜ)
Cₚ = count(lat .== 0)/(Nₜ^2)
push!(p_cs,Cₚ)
break
end
end
end
# ╔═╡ 86be6a6c-ec68-49c6-a3ce-aa7cce5398c3
if length(p_cs)>0
sum(p_cs)/length(p_cs)
end
╠═╡ =#
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
@ -1858,6 +1843,7 @@ version = "1.4.1+0"
# ╔═╡ Cell order:
# ╟─d541a835-801c-46d7-b311-9f712ffb0eb0
# ╠═efa19006-6cc2-4180-8963-2b5b20affdcf
# ╠═8aa6eaee-9238-4e74-bffc-606f08562ea4
# ╟─ea1f7206-eea0-4014-a4fb-3c5f5e78660e
# ╟─7fff47f2-0795-4f4f-aa51-7dc0adf6992c
# ╠═18c0fbf2-07b1-4ec3-b364-2ce24ebf5a2a
@ -1872,10 +1858,6 @@ version = "1.4.1+0"
# ╟─47d8f7ec-0d76-4309-9beb-3c288489cb1a
# ╠═3972be44-ac1d-482f-9fe1-69c51c0815c4
# ╠═5d74efcc-4699-4a45-95d5-1029581f84aa
# ╠═340be4d1-e325-4e8d-b791-e6af5bd2e610
# ╠═1823f63d-e0f0-4867-a762-3ab234717e5f
# ╠═d812351e-5bcc-4de0-a0b0-3bb56f328391
# ╠═158d3a9c-c435-437e-bf0c-e184ef0e68d1
# ╠═5e2613e5-5f81-4d24-8e21-708039344754
# ╠═3c7cb57d-91b3-4f0a-a0f7-3f202b48fe57
# ╠═86be6a6c-ec68-49c6-a3ce-aa7cce5398c3
@ -1885,7 +1867,7 @@ version = "1.4.1+0"
# ╟─1251afa5-fc38-4967-9596-11c21f1b0322
# ╟─a4e70668-fb6d-4a5f-8326-feda865193d5
# ╠═c728553c-4d9d-4111-b3a1-6cffd64a472b
# ╟─ac0c427d-b9d1-48bc-8b8e-25fb1734c8f0
# ╠═ac0c427d-b9d1-48bc-8b8e-25fb1734c8f0
# ╟─69a26f6f-476d-469b-8ab4-bd1c39cf139d
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002