Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Summerstudent project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hendriks, David D Dr (PG/R - Maths & Physics)
Summerstudent project
Commits
93f3a092
Commit
93f3a092
authored
5 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
putting everything in 1 place
parent
734d2ab3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
maxwellian_kicks_python/maxwell.py
+65
-0
65 additions, 0 deletions
maxwellian_kicks_python/maxwell.py
with
65 additions
and
0 deletions
maxwellian_kicks_python/maxwell.py
0 → 100644
+
65
−
0
View file @
93f3a092
import
math
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
scipy.special
import
erf
import
random
# Hnn
# http://pulsars.info/Thesis.pdf
# https://arxiv.org/pdf/1807.11489.pdf
# http://mathworld.wolfram.com/MaxwellDistribution.html
# Give different formulae
# Especially the first factor is a bit unclear sometimes
def
maxwell_prob_density
(
vkick
,
dispersion
):
return
np
.
sqrt
(
2.0
/
np
.
pi
)
*
(
vkick
**
2
)
/
(
dispersion
**
3
)
*
np
.
exp
(
-
((
vkick
**
2
)
/
(
2
*
(
dispersion
**
2
))))
def
maxwell_cum_density
(
vkick
,
dispersion
):
return
erf
((
vkick
)
/
(
np
.
sqrt
(
2
)
*
dispersion
))
-
((
vkick
*
np
.
exp
(
-
((
vkick
**
2
)
/
(
2
*
(
dispersion
**
2
)))))
/
(
dispersion
))
*
(
np
.
sqrt
(
2.0
/
math
.
pi
))
# sampling from distribution:
def
sample_maxwell
(
sigma
):
X
=
random
.
random
()
Y
=
random
.
random
()
W
=
random
.
random
()
Z
=
random
.
random
()
s
=
sigma
*
math
.
sqrt
(
-
2
*
math
.
log
(
1
-
X
))
p
=
sigma
*
math
.
sqrt
(
-
2
*
math
.
log
(
1
-
Y
))
theta
=
2
*
math
.
pi
*
Y
phi
=
2
*
math
.
pi
*
Z
u
=
s
*
math
.
cos
(
theta
)
v
=
s
*
math
.
sin
(
theta
)
w
=
p
*
math
.
cos
(
phi
)
kick
=
math
.
sqrt
((
u
**
2
)
+
(
v
**
2
)
+
(
w
**
2
))
return
kick
dispersion
=
265
samples
=
50000
sampled_array
=
[
sample_maxwell
(
dispersion
)
for
_
in
range
(
samples
)]
v_arr
=
np
.
arange
(
0
,
1500
,
1
)
mw_prob
=
maxwell_prob_density
(
v_arr
,
dispersion
)
mw_cum
=
maxwell_cum_density
(
v_arr
,
dispersion
)
fig
,
axes
=
plt
.
subplots
(
nrows
=
1
,
ncols
=
2
)
axes
[
0
].
plot
(
v_arr
,
mw_prob
)
axes
[
0
].
hist
(
sampled_array
,
density
=
True
,
bins
=
100
)
axes
[
0
].
set_ylabel
(
'
Probability density
'
)
axes
[
0
].
set_xlabel
(
'
v (km s-1)
'
)
axes
[
1
].
plot
(
v_arr
,
mw_cum
)
axes
[
1
].
set_ylabel
(
'
Cumulative density
'
)
axes
[
1
].
set_xlabel
(
'
v (km s-1)
'
)
plt
.
show
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment