ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 21 Jan 2012 18:25:05 +0100Symbolic expectations and double integralshttps://ask.sagemath.org/question/8648/symbolic-expectations-and-double-integrals/I'd like to compute the following expectation ($U$ and $V$ are independent and normally distributed or Gaussian)
$a_{k,p}=E(|U|^p|U+\sqrt{k-1}V|^p)$
Is there a way to directly compute those expectations in Sage ?
If I write it down, I obtain a double integral which I already tried to compute with maxima like this (ok here, you can only see the starting point with the inner integral with respect to $v$ first)
load(distrib);
n(x):=pdf_normal(x, 0, 1);
inner_integral: integrate(abs(u+sqrt(k-1)*v)^p*n(v), v, minf, inf);
but to no avail.
NB: The absolute central moment $a_{1,p/2}$ can be easily obtained with maxima with
ratsimp(integrate(abs(x)^p*n(x), x, minf, inf));
but no 'simple' expression as for the aforementioned double integral.
Any hint?Sat, 21 Jan 2012 09:07:56 +0100https://ask.sagemath.org/question/8648/symbolic-expectations-and-double-integrals/Comment by Green diod for <p>I'd like to compute the following expectation ($U$ and $V$ are independent and normally distributed or Gaussian)
$a_{k,p}=E(|U|^p|U+\sqrt{k-1}V|^p)$</p>
<p>Is there a way to directly compute those expectations in Sage ?</p>
<p>If I write it down, I obtain a double integral which I already tried to compute with maxima like this (ok here, you can only see the starting point with the inner integral with respect to $v$ first)</p>
<pre><code>load(distrib);
n(x):=pdf_normal(x, 0, 1);
inner_integral: integrate(abs(u+sqrt(k-1)*v)^p*n(v), v, minf, inf);
</code></pre>
<p>but to no avail.</p>
<p>NB: The absolute central moment $a_{1,p/2}$ can be easily obtained with maxima with</p>
<pre><code>ratsimp(integrate(abs(x)^p*n(x), x, minf, inf));
</code></pre>
<p>but no 'simple' expression as for the aforementioned double integral.</p>
<p>Any hint?</p>
https://ask.sagemath.org/question/8648/symbolic-expectations-and-double-integrals/?comment=20467#post-id-20467@kcrisman I thought that sometimes Sage could use sympy or some other CAS for symbolic integration. But then, I'm stuck here then. Sat, 21 Jan 2012 18:16:19 +0100https://ask.sagemath.org/question/8648/symbolic-expectations-and-double-integrals/?comment=20467#post-id-20467Comment by kcrisman for <p>I'd like to compute the following expectation ($U$ and $V$ are independent and normally distributed or Gaussian)
$a_{k,p}=E(|U|^p|U+\sqrt{k-1}V|^p)$</p>
<p>Is there a way to directly compute those expectations in Sage ?</p>
<p>If I write it down, I obtain a double integral which I already tried to compute with maxima like this (ok here, you can only see the starting point with the inner integral with respect to $v$ first)</p>
<pre><code>load(distrib);
n(x):=pdf_normal(x, 0, 1);
inner_integral: integrate(abs(u+sqrt(k-1)*v)^p*n(v), v, minf, inf);
</code></pre>
<p>but to no avail.</p>
<p>NB: The absolute central moment $a_{1,p/2}$ can be easily obtained with maxima with</p>
<pre><code>ratsimp(integrate(abs(x)^p*n(x), x, minf, inf));
</code></pre>
<p>but no 'simple' expression as for the aforementioned double integral.</p>
<p>Any hint?</p>
https://ask.sagemath.org/question/8648/symbolic-expectations-and-double-integrals/?comment=20470#post-id-20470Since Sage uses Maxima for all of its symbolic integration, I find it unlikely we'll do better. We do have numerical routines of various types, but I don't think this is what you are looking for.Sat, 21 Jan 2012 16:45:52 +0100https://ask.sagemath.org/question/8648/symbolic-expectations-and-double-integrals/?comment=20470#post-id-20470Answer by Green diod for <p>I'd like to compute the following expectation ($U$ and $V$ are independent and normally distributed or Gaussian)
$a_{k,p}=E(|U|^p|U+\sqrt{k-1}V|^p)$</p>
<p>Is there a way to directly compute those expectations in Sage ?</p>
<p>If I write it down, I obtain a double integral which I already tried to compute with maxima like this (ok here, you can only see the starting point with the inner integral with respect to $v$ first)</p>
<pre><code>load(distrib);
n(x):=pdf_normal(x, 0, 1);
inner_integral: integrate(abs(u+sqrt(k-1)*v)^p*n(v), v, minf, inf);
</code></pre>
<p>but to no avail.</p>
<p>NB: The absolute central moment $a_{1,p/2}$ can be easily obtained with maxima with</p>
<pre><code>ratsimp(integrate(abs(x)^p*n(x), x, minf, inf));
</code></pre>
<p>but no 'simple' expression as for the aforementioned double integral.</p>
<p>Any hint?</p>
https://ask.sagemath.org/question/8648/symbolic-expectations-and-double-integrals/?answer=13164#post-id-13164Suppose `n(x)` was defined somehow (in fact, in extenso) but see also my related question about how to [import Maxima built-in/package functions](http://ask.sagemath.org/question/1079/defining-symbolic-functions-in-sage-and-importing). My current result so far:
absm(p)=integral(abs(x)^p*n(x), x, -infinity, infinity)
absm
p |--> 2^(1/2*p)*gamma(1/2*p + 1/2)/sqrt(pi)
a(k,p)=integral(integral(abs(u)^p*abs(u+sqrt(k-1)*v)^p*n(v)*n(u), v, -infinity, infinity), u, -infinity, infinity)
a(k,p)
1/2*integrate(abs(u)^p*integrate(abs(sqrt(k - 1)*v + u)^p*e^(-1/2*u^2 - 1/2*v^2), v, -Infinity, +Infinity), u, -Infinity, +Infinity)/pi
ab(p)=a(1,p/2).simplify()
ab
p |--> 2^(1/2*p)*gamma(1/2*p + 1/2)/sqrt(pi)
bool(absm == ab)
True
This is a partial result but `a(k,p)` can't be simplified in terms of gamma's or whatnots.
How do you make changes of variables in Sage?
Sat, 21 Jan 2012 18:25:05 +0100https://ask.sagemath.org/question/8648/symbolic-expectations-and-double-integrals/?answer=13164#post-id-13164