Monte Carlo and Metropolis algorithm added.
This commit is contained in:
parent
e74cf7e062
commit
120fabe751
|
@ -0,0 +1,38 @@
|
||||||
|
### A Pluto.jl notebook ###
|
||||||
|
# v0.19.27
|
||||||
|
|
||||||
|
using Markdown
|
||||||
|
using InteractiveUtils
|
||||||
|
|
||||||
|
# ╔═╡ 02ba7cbc-468d-11ee-2deb-2d1be28da1c0
|
||||||
|
md"""
|
||||||
|
# Numberical Integration
|
||||||
|
|
||||||
|
There is a simple way of calculation of an integral: using the defenition of integration. For function $f(x)$, we have the integral
|
||||||
|
|
||||||
|
$I = \int_{a}^{b} f(x) \mathrm{d}x = \sum_{i=1}^{N} f(x_i) h$
|
||||||
|
|
||||||
|
Where $x_i = a + hi$. The key idea is that if we reduce the value of $h$, it'll be decrease the error $\Delta$, but if we continue, $\Delta$ will increase!
|
||||||
|
|
||||||
|
Lets do an experiment.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# ╔═╡ ce049874-6be1-4b69-b846-186e047f9579
|
||||||
|
"integral of function `f` from `a` to `b`"
|
||||||
|
function integral(f::Function, a::Float64, b::Float64, N::Int64)
|
||||||
|
h = (a+b)/N
|
||||||
|
X = a:h:b
|
||||||
|
I = sum(h*X)
|
||||||
|
end
|
||||||
|
|
||||||
|
# ╔═╡ 7ab92ecf-e2b5-4b97-991a-302dc5399917
|
||||||
|
f(x) = x.^2
|
||||||
|
|
||||||
|
# ╔═╡ 94a22398-cb45-40b9-8810-a564e58d7856
|
||||||
|
I = integral(f, 0.0, 2.0, 10)
|
||||||
|
|
||||||
|
# ╔═╡ Cell order:
|
||||||
|
# ╟─02ba7cbc-468d-11ee-2deb-2d1be28da1c0
|
||||||
|
# ╠═ce049874-6be1-4b69-b846-186e047f9579
|
||||||
|
# ╠═7ab92ecf-e2b5-4b97-991a-302dc5399917
|
||||||
|
# ╠═94a22398-cb45-40b9-8810-a564e58d7856
|
|
@ -1,5 +1,5 @@
|
||||||
### A Pluto.jl notebook ###
|
### A Pluto.jl notebook ###
|
||||||
# v0.19.25
|
# v0.19.27
|
||||||
|
|
||||||
using Markdown
|
using Markdown
|
||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
|
@ -36,7 +36,7 @@ In percolation theory, we have a *critical probability*, $p_c$ which is for $p <
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ╔═╡ 8aa6eaee-9238-4e74-bffc-606f08562ea4
|
# ╔═╡ 8aa6eaee-9238-4e74-bffc-606f08562ea4
|
||||||
pl₁ = simshow(repeat((sample(1:-1:0, weights([0.75, 1-0.75]), (100,100))), inner = (10, 10)))
|
pl₁ = simshow(repeat((sample(1:-1:0, weights([0.6, 1-0.6]), (100,100))), inner = (10, 10)))
|
||||||
|
|
||||||
# ╔═╡ ea1f7206-eea0-4014-a4fb-3c5f5e78660e
|
# ╔═╡ ea1f7206-eea0-4014-a4fb-3c5f5e78660e
|
||||||
md""" p= $(@bind p NumberField(0.01:0.01:1, default = 0.5))"""
|
md""" p= $(@bind p NumberField(0.01:0.01:1, default = 0.5))"""
|
||||||
|
|
|
@ -147,8 +147,16 @@ end
|
||||||
"Returns a two dimentional Levy flight."
|
"Returns a two dimentional Levy flight."
|
||||||
function levy_flight(N)
|
function levy_flight(N)
|
||||||
α = rand( (0:0.01:(2*π)), N)
|
α = rand( (0:0.01:(2*π)), N)
|
||||||
r = [cdf_levy(rand(), 1.5) for i in 1:N]
|
r = []
|
||||||
|
|
||||||
|
p = .95
|
||||||
|
for i in 1:N
|
||||||
|
if rand()>p
|
||||||
|
push!(r, rand( (5:0.5:6) ))
|
||||||
|
else
|
||||||
|
push!(r, rand( (0.1:0.1:1.0) ))
|
||||||
|
end
|
||||||
|
end
|
||||||
xs = r .* cos.(α)
|
xs = r .* cos.(α)
|
||||||
ys = r .* sin.(α)
|
ys = r .* sin.(α)
|
||||||
|
|
||||||
|
@ -1224,12 +1232,12 @@ version = "1.4.1+0"
|
||||||
# ╔═╡ Cell order:
|
# ╔═╡ Cell order:
|
||||||
# ╟─50b71a10-26d0-11ee-15e0-1b9fb9742c6c
|
# ╟─50b71a10-26d0-11ee-15e0-1b9fb9742c6c
|
||||||
# ╠═0bdb9051-3b5f-4ede-8b61-4bbe07b30b5a
|
# ╠═0bdb9051-3b5f-4ede-8b61-4bbe07b30b5a
|
||||||
|
# ╟─33a61359-0eaf-41d8-a7c4-bbc5bfa3e394
|
||||||
# ╟─dbe07cd8-87f4-463f-8b85-5edb1c9c2447
|
# ╟─dbe07cd8-87f4-463f-8b85-5edb1c9c2447
|
||||||
# ╠═9a91b8d9-c407-4092-ab87-bbf0f833b417
|
# ╠═9a91b8d9-c407-4092-ab87-bbf0f833b417
|
||||||
# ╠═164c1ec3-0970-414d-9826-ac8833b55c28
|
# ╠═164c1ec3-0970-414d-9826-ac8833b55c28
|
||||||
# ╟─9f7e87d7-2197-421b-97e1-8e183fb9c003
|
# ╟─9f7e87d7-2197-421b-97e1-8e183fb9c003
|
||||||
# ╟─e7de8942-df19-45a3-a8f6-18b900c8453c
|
# ╟─e7de8942-df19-45a3-a8f6-18b900c8453c
|
||||||
# ╟─33a61359-0eaf-41d8-a7c4-bbc5bfa3e394
|
|
||||||
# ╠═9d411317-cda3-4954-b5df-fab5fc2c95f9
|
# ╠═9d411317-cda3-4954-b5df-fab5fc2c95f9
|
||||||
# ╟─fdcf6325-464a-4a84-8218-6156b76c49bd
|
# ╟─fdcf6325-464a-4a84-8218-6156b76c49bd
|
||||||
# ╟─0595936a-34a3-48fb-9acb-1786d8bbf810
|
# ╟─0595936a-34a3-48fb-9acb-1786d8bbf810
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue