MATLAB: Help with Monte Carlo sim

integrationmonte carlo

Im messing around with the montecarlo function for integration and ran into a problem. The y bounds are between x^2 and x^3 and x are between 0 and 1. Heres the code I have so far but can't figure out how to deal with the y bounds.
N=1000; Landed=0;
for i=1:N x=rand()*1; y=rand()* Landed=Landed+1 end disp('Calculated Area Size:') area=

Best Answer

That code won't even run. Even if it did, your x and y are just rand() which goes between 0 and 1. The y bounds have nothing at all to do with x, x^2 or x^3, but since they all use rand, everything will be between 0 and 1. If you want some higher value, multiply rand() by some amplification factor.
I'm attaching my Monte Carlo demos, for what it's worth.