Monte carlo integral evaluation

randonmind
Messages
2
Reaction score
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
What error messages are you gettting and what programming language are you using?
 
it is in Matlab:
Error in ==> MCexam3 at 13
x1(i+1)=x(i)+1/N*random('normal',0,1).^2
 
are you mixing up your big N and little n ? in the for loop you use n, but you haven't defined it anywhere.
 
Thread 'Use greedy vertex coloring algorithm to prove the upper bound of χ'
Hi! I am struggling with the exercise I mentioned under "Homework statement". The exercise is about a specific "greedy vertex coloring algorithm". One definition (which matches what my book uses) can be found here: https://people.cs.uchicago.edu/~laci/HANDOUTS/greedycoloring.pdf Here is also a screenshot of the relevant parts of the linked PDF, i.e. the def. of the algorithm: Sadly I don't have much to show as far as a solution attempt goes, as I am stuck on how to proceed. I thought...
Back
Top