Monte Carlo and Metropolis algorithm added.

This commit is contained in:
Milo Jamali 2023-09-01 19:38:17 +03:30
parent e74cf7e062
commit 120fabe751
4 changed files with 1188 additions and 4 deletions

View File

@ -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

View File

@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.19.25
# v0.19.27
using Markdown
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
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
md""" p= $(@bind p NumberField(0.01:0.01:1, default = 0.5))"""

View File

@ -147,8 +147,16 @@ end
"Returns a two dimentional Levy flight."
function levy_flight(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.(α)
ys = r .* sin.(α)
@ -1224,12 +1232,12 @@ version = "1.4.1+0"
# ╔═╡ Cell order:
# ╟─50b71a10-26d0-11ee-15e0-1b9fb9742c6c
# ╠═0bdb9051-3b5f-4ede-8b61-4bbe07b30b5a
# ╟─33a61359-0eaf-41d8-a7c4-bbc5bfa3e394
# ╟─dbe07cd8-87f4-463f-8b85-5edb1c9c2447
# ╠═9a91b8d9-c407-4092-ab87-bbf0f833b417
# ╠═164c1ec3-0970-414d-9826-ac8833b55c28
# ╟─9f7e87d7-2197-421b-97e1-8e183fb9c003
# ╟─e7de8942-df19-45a3-a8f6-18b900c8453c
# ╟─33a61359-0eaf-41d8-a7c4-bbc5bfa3e394
# ╠═9d411317-cda3-4954-b5df-fab5fc2c95f9
# ╟─fdcf6325-464a-4a84-8218-6156b76c49bd
# ╟─0595936a-34a3-48fb-9acb-1786d8bbf810

File diff suppressed because it is too large Load Diff