# Monte Carlo Integration Program In Fortran

A MONTE CARLO METHOD FOR APPROXIMATING INTEGRALS A MONTE CARLO METHOD FOR APPROXIMATING INTEGRALS This article is contributed. Mon.te Car.lo-a town in Monaco principality, in SE France: a gambling resort. ( The Random House Dictionary) The term 'Monte Carlo methods' implies those techniques which rely on the simulation of random or chance processes such as the tossing of a dice or a coin. In this article, we look at a simple Monte Carlo method for approximating the definite integral For simplicity, let us assume that the function f is such that f( x) 0 over the interval of integration a, b. With reference to a Cartesian coordinate frame Oxy, the definite integral then represents the area of the region bounded the curve y = f( x), the vertical lines x = a and x = b and the x-axis.

### Monte Carlo Integration Code

Numerical Integration and. The following program implements Simpson’s rule in FORTRAN. The following program implements. Is that of Monte Carlo integration.

1. A simulation program. Monte Carlo integration. Simulating quantum ﬁeld theories numerically is an important application for Monte Carlo simulation methods.
2. Monte Carlo methods. Works with: Fortran version 90 and later. MODULE Simulation. PROGRAM MONTE_CARLO. Let us denote the region by R. Refer to Figure 1. In Figure 1, the rectangle ABCD is such that the sides CD and AB have length b - a and AC and BD have length h, where h is greater than or equal to the maximum value of f( x) over the interval a, b. If we are throwing darts at random into the region inside the rectangle ABCD, the chance or probability p that a dart hits the region R is given by the area of R divided by the area of ABCD, i.e. By As an example, if the region R covers half the rectangular region, it is clear that there is a 50% chance of the dart hitting region R, hence p = 1/2.

Now, for a given function f( x) over a given interval a, b, if we know what p is, we calculate the definite integral by We can estimate the value of p by actually throwing randomly many darts into the region enclosed by the rectangular ABCD. The estimated value of p is then given by and the required value of the definite integral is given approximately by Instead of throwing an actual dart into the rectangular region, we can simulate a throw on the computer by using the pseudorandom number function to generate a 'random' number u lying between a and b and also a 'random' number v between 0 and h. The simulated throw hits the point ( u, v) inside the rectangle ABCD. To determine whether the throw hits the region R, we check whether v £ f( u). If v £ f( u), the throw hits R.

Otherwise, it is outside R. Thousands or millions of random throws can be virtually carried out without hurting one’s arm! All that one needs to do is to write a computer program to carry out the simulation. The results of the simulated throws can then be used to estimate the probability p and hence the value of the definite integral. Thus, we have a Monte Carlo method for estimating the definite integral. We have written a FORTRAN program for the Monte Carlo method for estimating the integral of the function f( x) = x 2 over the interval 1, 2.

In the program, we take h = 4. Program montecarlo print., ’Enter no. Of throws ’ read., nthrow a=1.0 b=2.0 h=4.0 nhit=0 do 10 j=1,nthrow call random(ru) call random(rv) u=a+(b-a).ru v=rv.h if (v.le.F(u)) nhit=nhit+1 10 continue estprob=float(nhit)/float(nthrow) estint=estprob.h.(b-a) print.,’Estimated value of the integral is’,estint end function F(x) F=x.x return end When we run the above problem with 50000 throws, the output is 2.3278.

The actual (exact) value of the integral is 7/3 or 2.3333. Thus, the value of the integral as estimated using the Monte Carlo method, i.e. 2.3278, is reasonably close to the actual one. The discussion above assumes that f( x) 0 over the interval of integration. The method can, however, be easily modified to take into consideration a more general function.

ADVERTISEMENT ADVERTISEMENT.

### Integration Program In Belgium

I am attempting to do a Monte Carlo simulation using RANDOMNUMBER. I am using gFortran. I want to perform the following:. Calculate monteNum (fixed number) and generate a random number, monteTest. If monteNum = monteTest, then generate another random number randPos which is used to select a row from an array. Otherwise, generate a new monteTest until step 2 is satisfied. Firstly, I tried to use a DO loop.

CALL RANDOMSEED monteNum = (countup + countdn)/(nReal.2)! This is just a number in 0,1. DO i = 1, 100 CALL RANDOMNUMBER (monteTest)! MonteTest is a randomly generated number used in Monte Carlo simulation IF (monteNum = monteTest) THEN CALL RANDOMNUMBER (randPos)! RandPos will be used to select one flippable position randomly Vpos = INT(randPos.count)!

Position of the chosen vertex; count is the length of fList flipVertex(1,:) = fList(Vpos,:) ELSE i = i+1 END IF END DO An error arises from the ELSE statement. Since it is not known that the IF statement will produce TRUE in 100 loops, I thought a DO WHILE was a better choice. MonteTest = 0.5! Setting the initial value. But ideally it should be random DO WHILE (monteNum.