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.Wed, 06 Mar 2013 13:09:49 +0100numerically integrating an expression containing 'i'https://ask.sagemath.org/question/9884/numerically-integrating-an-expression-containing-i/This is example of an integral that can't be evaluated using
sage: numerical_integral(i*sin(i*x), x, 0, 0.2)
Traceback (click to the left of this block for traceback)
...
TypeError: unable to coerce to a real number
even though the integrand is real (in disguse). How can I get around this problem?Wed, 06 Mar 2013 12:45:59 +0100https://ask.sagemath.org/question/9884/numerically-integrating-an-expression-containing-i/Answer by benjaminfjones for <p>This is example of an integral that can't be evaluated using </p>
<pre><code>sage: numerical_integral(i*sin(i*x), x, 0, 0.2)
Traceback (click to the left of this block for traceback)
...
TypeError: unable to coerce to a real number
</code></pre>
<p>even though the integrand is real (in disguse). How can I get around this problem?</p>
https://ask.sagemath.org/question/9884/numerically-integrating-an-expression-containing-i/?answer=14619#post-id-14619The integrand isn't a real for all (complex) values of x, though. If you wrap the symbolic part in an anonymous function that just does the evaluation (at real values of x in this integral) it will work:
sage: numerical_integral(lambda x: i*sin(i*x), 0, 0.2)
(-0.020066755619075848, 2.2278574117824245e-16)Wed, 06 Mar 2013 13:09:49 +0100https://ask.sagemath.org/question/9884/numerically-integrating-an-expression-containing-i/?answer=14619#post-id-14619Answer by calc314 for <p>This is example of an integral that can't be evaluated using </p>
<pre><code>sage: numerical_integral(i*sin(i*x), x, 0, 0.2)
Traceback (click to the left of this block for traceback)
...
TypeError: unable to coerce to a real number
</code></pre>
<p>even though the integrand is real (in disguse). How can I get around this problem?</p>
https://ask.sagemath.org/question/9884/numerically-integrating-an-expression-containing-i/?answer=14632#post-id-14632Your integrand is `-sinh(x)` and so you can do this using `integrate`.
f(x)=i*sin(i*x)
print f(x).simplify()
integrate(f(x), x, 0, 0.2)
gives
-sinh(x)
-0.0200667556191Wed, 06 Mar 2013 13:08:32 +0100https://ask.sagemath.org/question/9884/numerically-integrating-an-expression-containing-i/?answer=14632#post-id-14632