How do you program the Monte Carlo Integration method in Matlab?
<p>I am trying to figure out how to right a math based app with Matlab, although I cannot seem to figure out how to get the Monte Carlo method of integration to work. I feel that I do not have algorithm thought out correctly either. As of now, I have something like:</p>

<pre><code>    // For the function {integral of cos(x^3)*exp(x^(1/2))+x dx
    // from x = 0 to x = 10
    ans = 0;
    for i = 1:100000000
        x = 10*rand;
        ans = ans + cos(x^3)*exp(x^(1/2))+x
    end
</code></pre>

<p>I feel that this is completely wrong because my outputs are hardly even close to what is expected. How should I correctly write this? Or, how should the algorithm for setting this up look?</p>