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.Fri, 23 Feb 2018 07:51:36 +0100How to do numerical integral where the answer still have variables in it?https://ask.sagemath.org/question/41225/how-to-do-numerical-integral-where-the-answer-still-have-variables-in-it/I typed in
"numerical_integral(lambda d:exp(-(h-1)^2-(d-2)^2), 0,Infinity)"
and got
"unable to simplify to float approximation"
Are there anyway to compute the integral numerically and still leave a variable in the answer? Thanks,Wed, 21 Feb 2018 22:13:07 +0100https://ask.sagemath.org/question/41225/how-to-do-numerical-integral-where-the-answer-still-have-variables-in-it/Answer by tmonteil for <p>I typed in </p>
<p>"numerical_integral(lambda d:exp(-(h-1)^2-(d-2)^2), 0,Infinity)"</p>
<p>and got </p>
<p>"unable to simplify to float approximation"</p>
<p>Are there anyway to compute the integral numerically and still leave a variable in the answer? Thanks,</p>
https://ask.sagemath.org/question/41225/how-to-do-numerical-integral-where-the-answer-still-have-variables-in-it/?answer=41227#post-id-41227The general answer is no. In your case, you can easily isolate `h` and `d` since $exp(x+y)=exp(x)+exp(y)$. Note also that the integral can be computed symbolically:
sage: var('d h')
(d, h)
sage: integral(exp(-(h-1)^2-(d-2)^2), d,0,Infinity)
1/2*sqrt(pi)*erf(2)*e^(-h^2 + 2*h - 1) + 1/2*sqrt(pi)*e^(-h^2 + 2*h - 1)Thu, 22 Feb 2018 01:09:03 +0100https://ask.sagemath.org/question/41225/how-to-do-numerical-integral-where-the-answer-still-have-variables-in-it/?answer=41227#post-id-41227Comment by Emmanuel Charpentier for <p>The general answer is no. In your case, you can easily isolate <code>h</code> and <code>d</code> since $exp(x+y)=exp(x)+exp(y)$. Note also that the integral can be computed symbolically:</p>
<pre><code>sage: var('d h')
(d, h)
sage: integral(exp(-(h-1)^2-(d-2)^2), d,0,Infinity)
1/2*sqrt(pi)*erf(2)*e^(-h^2 + 2*h - 1) + 1/2*sqrt(pi)*e^(-h^2 + 2*h - 1)
</code></pre>
https://ask.sagemath.org/question/41225/how-to-do-numerical-integral-where-the-answer-still-have-variables-in-it/?comment=41239#post-id-41239> since exp(x+y)=exp(x)+exp(y)
Huh ? I didn't know that.
I'll have to get back to high school. Damn...
More seriously, this is the typo of the death...Fri, 23 Feb 2018 07:51:36 +0100https://ask.sagemath.org/question/41225/how-to-do-numerical-integral-where-the-answer-still-have-variables-in-it/?comment=41239#post-id-41239