Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Luter 345 Experiments
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Creating the Simulation Environment
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Get shortened URL
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Algorithm for an Arbitrary Probability Distribution=== Often when generating particles in a simulation, particle energies, directions, and other properties are governed by a probability distribution. This being the case, a simple algorithm for applying arbitrary probability functions in a program is presented below. It should be noted that there are other methods to apply probability distributions and this is not a particularly efficient one, so if a simulation is large it may be beneficial to find another method. However, the method presented is very simple to apply, and thus is a good option for projects when efficiency is not a major concern. (0) Begin loop (1) Choose a random x value (2) Calculate P(x) of the randomly chosen value (must be adjusted, see note below) (3) Choose a random value between zero and one (uniformRand() function) (4) Compare the random number with the probability of the x value in question (4.a) If P(x) > uniRand : keep the value x (exit loop) (4.b) If P(x) < uniRand : discard the value of x (repeat the loop) It is of great important the maximum value of P(x), where x is the classical variable, is one. To achieve this, find the value of x where P(x) is at its maximum, x_max, and divide each P(x) in the algorithm by P(x_max). Using this method the algorithm will return x values in accordance with the defined probability distribution.
Summary:
Please note that all contributions to Luter 345 Experiments may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Luter 345 Experiments:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)