ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 23 Nov 2017 09:28:19 -0600Numerical approximation of multiple integralhttp://ask.sagemath.org/question/39733/numerical-approximation-of-multiple-integral/ 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''`
2. How to integrate multiple integrals with different $A_i$.Wed, 22 Nov 2017 14:05:37 -0600http://ask.sagemath.org/question/39733/numerical-approximation-of-multiple-integral/Answer by mforets for <p>I want to numerical integrate:</p>
<p>$$\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$.</p>
<p>I faced with several problems:</p>
<ol>
<li>I can't integrate even this simply integral: </li>
</ol>
<p>import scipy.stats as st</p>
<p>integrate(st.norm.pdf(x), x)</p>
<p>The result is error: <code>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''</code></p>
<ol>
<li>How to integrate multiple integrals with different $A_i$.</li>
</ol>
http://ask.sagemath.org/question/39733/numerical-approximation-of-multiple-integral/?answer=39744#post-id-39744For numerical integrals in Sage, use [numerical_integral](http://doc.sagemath.org/html/en/reference/calculus/sage/calculus/integration.html#sage.calculus.integration.numerical_integral). The function [integrate](http://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/integration/integral.html#sage.symbolic.integration.integral.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](https://members.loria.fr/PZimmermann/sagebook/integration.pdf).Thu, 23 Nov 2017 09:28:19 -0600http://ask.sagemath.org/question/39733/numerical-approximation-of-multiple-integral/?answer=39744#post-id-39744