Monte carlo integral evaluation

In summary, the conversation is about evaluating a Gaussian integral using the equation K=E[X^2] ∼Kn=1/N sum(x^2). The person has written some code in Matlab, but is receiving error messages. Another person suggests that the error may be due to mixing up the variables n and N in the for loop.
  • #1
randonmind
2
0
Hello
I need to evaluate Gaussian integral
K=1/(sqrt(2pi) int(-infinity +infinity) x^2 exp(-x^2/2) dx
by using
K=E[X^2] ∼Kn=1/N sum(x^2)
where x follows a normal distribution.
So far I have written this:
N=1000;
for i=1:n
x1(i+1)=x(i)+1/N*random('normal',0,1).^2
end
x1
but I am getting error messages.

Can anyone share their wisdom?
Thanks
Andreas
 
Physics news on Phys.org
  • #2
What error messages are you gettting and what programming language are you using?
 
  • #3
it is in Matlab:
Error in ==> MCexam3 at 13
x1(i+1)=x(i)+1/N*random('normal',0,1).^2
 
  • #4
are you mixing up your big N and little n ? in the for loop you use n, but you haven't defined it anywhere.
 

FAQ: Monte carlo integral evaluation

What is Monte Carlo integral evaluation?

Monte Carlo integral evaluation is a numerical method used to estimate the value of a definite integral by randomly sampling points within the integration domain and calculating the average of the function values at those points.

How does Monte Carlo integral evaluation work?

In Monte Carlo integral evaluation, a large number of random points are generated within the integration domain. The average of the function values at these points is then multiplied by the area of the integration domain to approximate the value of the integral.

What are the advantages of using Monte Carlo integral evaluation?

Monte Carlo integral evaluation can be applied to a wide range of functions and is not limited by the complexity of the integrand. It also has a high degree of accuracy, with the error decreasing as the number of sampled points increases.

What are the limitations of Monte Carlo integral evaluation?

Monte Carlo integral evaluation can be computationally expensive, especially when the integration domain is high-dimensional. It also requires a large number of sampled points to achieve a desired level of accuracy, which can be time-consuming.

How is Monte Carlo integral evaluation different from other numerical integration methods?

Unlike traditional numerical integration methods, Monte Carlo integral evaluation does not require the integrand to be known in a closed form. It also has the advantage of being able to handle high-dimensional integrals, which can be challenging for other methods.

Back
Top