- #1
steven187
- 176
- 0
Dear friends
I have been trying to write a code in Mathematica for solving a double integral with a non rectangular region through monte carlo integration, I have written a code that will solve for rectangular regions but i have no idea how to change it to work for non rectangular regions
for example let the function be fun[x_,y_] := 2x
what do i need to do to make this code to solve it for the non rectangular region {(x,y):y<=x<=4y,0<=y<=2}
fun[x_,y_] := 2x
a =
b =
c =
d =
Monte2D[n_]:=(b-a)*(d-c)/n*Sum[fun[Random[Real,{a,b}],Random[Real,{c,d}]],{n}]
nsamples=1000; nrepetitions=100;
mc=Table[Monte2D[nsamples],{nrepetitions}];
Print["For n=",nsamples," with ",nrepetitions," repetitions, \
mean=",Mean[mc]," st.dev.=",StandardDeviation[mc]
Please help
I have been trying to write a code in Mathematica for solving a double integral with a non rectangular region through monte carlo integration, I have written a code that will solve for rectangular regions but i have no idea how to change it to work for non rectangular regions
for example let the function be fun[x_,y_] := 2x
what do i need to do to make this code to solve it for the non rectangular region {(x,y):y<=x<=4y,0<=y<=2}
fun[x_,y_] := 2x
a =
b =
c =
d =
Monte2D[n_]:=(b-a)*(d-c)/n*Sum[fun[Random[Real,{a,b}],Random[Real,{c,d}]],{n}]
nsamples=1000; nrepetitions=100;
mc=Table[Monte2D[nsamples],{nrepetitions}];
Print["For n=",nsamples," with ",nrepetitions," repetitions, \
mean=",Mean[mc]," st.dev.=",StandardDeviation[mc]
Please help