[SciPy-User] question about numerical integration
Daπid
davidmenhur at gmail.com
Sat May 3 08:31:05 EDT 2014
On 3 May 2014 13:02, K. Sun <sunk.cs at gmail.com> wrote:
> My question is: is there any way to control the number of
> calls to f(x,y), e.g. <= 10000. I only need a rough estimation
> and can tolerant +-10% error.
That is a good case for Monte Carlo integration. The error goes as
1/sqrt(N) independently of the number of dimensions, so you will be there
with a few hundred evaluations. In the classic example to compute pi:
In [3]: x = np.random.random(100)
In [4]: y = np.random.random(100)
In [5]: np.sum(x*x + y*y < 1)
Out[5]: 78
In [6]: 4.0 * np.sum(x*x + y*y < 1)/100.
Out[6]: 3.12
where the function is x^2 + y^2.
/David.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140503/fd8e8ce8/attachment.html>
More information about the SciPy-User
mailing list