Use Monte Carlo to simulate the ball π value.

Source: Internet
Author: User

Use Monte Carlo to simulate the ball π value.

The Monte Carlo (Monte Carlo) method, also known as the random sampling or statistical test method, is a branch of computational mathematics, it was developed in the 1940s s to adapt to the development of the atomic energy industry at that time. The traditional empirical method is difficult to obtain satisfactory results because it cannot approach the real physical process. Because the Monte Carlo method can simulate the actual physical process, the solution is very consistent with the actual solution, the results are satisfactory. This is why we adopt this method.

  

Edit basic principles and ideas

 

When the problem to be solved is the probability of an event or the expected value of a random variable, they can use a "test" method to obtain the frequency of such an event, or the average value of this random variable, and use them as the solution to the problem. This is the basic idea of the Monte Carlo method. The Monte Carlo method captures the geometric quantity and geometric characteristics of the motion of a thing and simulates it using mathematical methods, that is, a digital simulation experiment. It is based on a probability model. Based on the process described in this model, it simulates the experiment results and serves as the approximate solution of the problem. The Monte Carlo solution can be divided into three main steps: constructing or describing probability processes, sampling from known probability distributions, and establishing various estimator.

 

 

 

Three major steps for solving Monte Carlo Problems

 

Construct or describe the probability process:

 

For random problems, such as particle transport, the probability process is described and simulated correctly. For deterministic problems that are not random, such as the calculation of definite points, the probability process of a person must be constructed in advance, and some of its parameters are exactly the solutions to the required problem. That is, we need to convert non-random problems into random problems.

 

Sample from known probability distribution:

 

After the probability model is constructed, various probability models can be considered to be composed of various probability distributions, so random variables (or random vectors) with known probability distributions are generated ), it becomes the basic means to implement the Monte Carlo method simulation experiment, which is also the reason why the Monte Carlo method is called random sampling. The simplest, most basic, and most important probability distribution is the even distribution (or rectangular distribution) on (0, 1 ). A random number is a random variable with such an even distribution. A random number sequence is a simple subsample of a population with such distribution, that is, a sequence of independent random variables with such distribution. The random number generation problem is the sampling problem from this distribution. On a computer, you can use physical methods to generate random numbers. However, they are expensive and cannot be reused. Therefore, they are inconvenient to use. Another method is to use a mathematical recursive formula. The generated sequence is different from the real random number sequence, so it is called a pseudo-random number or a pseudo-random number sequence. However, a variety of statistical tests show that it is similar to a real random number or a random number sequence, so it can be used as a real random number. There are various methods for random sampling from known distributions. Different from the uniformly distributed sampling from (0, 1), these methods are implemented by means of random sequences, that is, they are all based on the premise of generating random numbers. We can see that random numbers are the basic tools for Monte Carlo simulation.

 

Create various estimator:

 

Generally, after a probability model is constructed and can be sampled from it, that is, after a simulated experiment is realized, we need to determine a random variable as the required solution to the problem, we call it unbiased estimation. The establishment of various estimator is equivalent to the investigation and registration of the simulation experiment results to obtain the solution to the problem. Example: A square with a side length of 2 draws a circle with a radius of 1 with a positive and assured center, and generates 0.1 billion random points in the square at random, probability of falling in the circle = circular area/square area = π/4. Run the following java code:

Public class ConteCarloMode {
/** Main method */
Public static void main (String [] agrs ){
Final int NUMBER_OF_TRIALS = 100000000;
Int numberOfHits = 0;

For (int I = 0; I <NUMBER_OF_TRIALS; I ++ ){
Double x = Math. random () * 2-1;
Double y = Math. random () * 2-1;
If (x * x + y * y <= 1)
NumberOfHits ++;
}

Double pi = 4.0 * numberOfHits/NUMBER_OF_TRIALS;
System. out. println ("PI is" + pi );

}

}

The lab values are very close to 3.14.

 


Monte Carlo Simulation

Monte Carlo simulation is a method to repeatedly generate time series by setting random processes, calculate the parameter estimator and statistic, and then study its distribution characteristics. Specifically, when the number of reliability features of each unit in the system is known, but the reliability of the system is too complex, it is difficult to establish a precise mathematical model for Reliability Prediction or the model is too complex and inconvenient to use, the expected value of system reliability can be calculated using the random simulation method. As the number of simulation times increases, the prediction accuracy also increases. Due to the repeated generation of time series, Monte Carlo simulation is based on high-capacity and high-speed computers. Therefore, it has been widely used in recent years.
Monte Carlo simulated the term was proposed by American physicist Metropolis during the Second World War to execute the Manhattan program.
The principle of Monte Carlo simulation is that when the problem or the object itself has a probability feature, a computer simulation method can be used to generate a sample result and calculate the statistic or parameter value based on the sample; with the increase of the number of simulation times, we can obtain a stable conclusion by calculating the average of the statistical values or parameter estimates.
Monte Carlo Simulation Method
Using this method to solve engineering technical problems can be divided into two types: deterministic problems and random problems.
The steps are as follows:
1. A simple and applicable probability model or random model is constructed based on the proposed problem, so that the solution of the problem corresponds to some features of the random variables in the model (such as probability, mean, and other features ), the constructed model must be consistent with the actual problem or system in terms of main feature parameters.
2. According to the distribution of various random variables in the model, a random number is generated on the computer to implement a sufficient number of random numbers required for a simulation process. Generally, a random number with a uniform distribution is generated first and then a random number following a certain distribution is generated before a random simulation test can be conducted.
3. based on the characteristics of the probability model and the distribution characteristics of random variables, a proper sampling method is designed and selected, sample each random variable (including direct sampling, stratified sampling, related sampling, and important sampling ).
4. Perform simulation tests and calculations based on the model to find the random solution to the problem.
5. Statistical analysis of the simulation test results, giving the probability solution of the problem and the accuracy estimation of the solution.

Application fields of Monte Carlo Simulation
The Monte Carlo simulation method is mainly used in the following fields:
1. directly apply Monte Carlo Simulation: use large-scale random numbers to simulate complex systems and obtain some parameters or important indicators.
2. Monte Carlo points: using random series to calculate points, the higher the dimension, the higher the integral efficiency.
3. MCMC: This is a promotion of the direct application of the Monte Carlo simulation method. The generation of random numbers in this method is in the Markov chain form.
 
Monte Carlo Simulation

I don't know what you want to ask. I 'd like to tell you how to use it to sample from the known probability distribution:
After the probability model is constructed, various probability models can be considered to be composed of various probability distributions, so random variables (or random vectors) with known probability distributions are generated ), it becomes the basic means to implement the Monte Carlo method simulation experiment, which is also the reason why the Monte Carlo method is called random sampling. The simplest, most basic, and most important probability distribution is the even distribution (or rectangular distribution) on (0, 1 ). A random number is a random variable with such an even distribution. A random number sequence is a simple subsample of a population with such distribution, that is, a sequence of independent random variables with such distribution. The random number generation problem is the sampling problem from this distribution. On a computer, you can use physical methods to generate random numbers. However, they are expensive and cannot be reused. Therefore, they are inconvenient to use.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.