Monte Carlo and Area -calculation
Question: It should be close to 0.3

    
    
    $ cat monte.py 
    import random,math
    density=int(1e6)
    x = [random.uniform(0,1)*7*math.pi for _ in range(density)]
    y = [random.uniform(0,1) for _ in range(density)]
    i = [math.sin(xx)*math.cos(xx) > yy for (xx,yy) in zip(x,y)]
    
    print sum(i)/(float(density)*10.0)*7*math.pi
    
    $ python monte.py 
    0.350184850795
    

I am trying to rewrite the below but for some reason the python code is not
even close.

    
    
    x = rand(1, 1000000)*7pi;
    y = rand(1, 1000000);
    i = sin(x).* cos(x) >y;
    Area3 = (sum(i) / 10000000)*7pi;
    


Answer: I'm getting identical results between your matlab and python versions... Are
you sure that the matlab version is giving you ~2, and not ~0.35?

For example:

MATLAB:

    
    
    x = rand(1, 1000000)*7*pi;
    y = rand(1, 1000000);
    i = sin(x).* cos(x) >y;
    Area3 = (sum(i) / 10000000)*7*pi
    

This yields: `0.3511`

Your pure-python version:

    
    
    import random,math
    density=int(1e6)
    x = [random.uniform(0,1)*7*math.pi for _ in range(density)]
    y = [random.uniform(0,1) for _ in range(density)]
    i = [math.sin(xx)*math.cos(xx) > yy for (xx,yy) in zip(x,y)]
    
    print sum(i)/(float(density)*10.0)*7*math.pi
    

This yields: `0.347935156296`

Numpy-based:

    
    
    import numpy as np
    x = np.random.random(1e6) * 7 * np.pi
    y = np.random.random(x.size)
    i = np.sin(x) * np.cos(x) > y
    print 7 * np.pi * i.sum() / (10 * x.size)
    

This yields: `0.350475133957`

