Ask Your Question
0

Numerical approximation of multiple integral

asked 2017-11-22 21:05:37 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I want to numerical integrate:

$$\int_{-\infty}^{A_1} \int_{-\infty}^{A_2-x_1} p(x_1)p(x_2)dx_1dx_2 ,$$ where $p(x_i)$ is a random variable that has a normal distribution with mean $\mu_i$ and standard deviation $\sigma_i$.

I faced with several problems:

  1. I can't integrate even this simply integral:

import scipy.stats as st

integrate(st.norm.pdf(x), x)

The result is error: TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

  1. How to integrate multiple integrals with different $A_i$.
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-11-23 16:28:19 +0100

mforets gravatar image

updated 2017-11-23 16:40:57 +0100

For numerical integrals in Sage, use numerical_integral. The function integrate is more appropriate for symbolic integration.

With your example:

sage: import scipy.stats as st
sage: numerical_integral(lambda x : st.norm.pdf(x), (-oo, 0.5))
(0.6914624612740132, 1.580169726891987e-09)

The first component is the value of the integral, and the second component is an error estimate.

As far as i'm aware, Sage does not expose a multi-dimensional numerical integration function. This can be worked around by a nested call to numerical_integral, but it will not be as efficient as it could be for some applications. There are more examples in Mathematical Computation with SageMath, Ch. 14, page 315.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-11-22 21:05:37 +0100

Seen: 927 times

Last updated: Nov 23 '17