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.Tue, 12 Mar 2019 17:30:13 -0500How can I detect failure of analytical integration?http://ask.sagemath.org/question/45729/how-can-i-detect-failure-of-analytical-integration/I want to check whether an analytical integration worked, and to try numerical integration in case it failed. I'd like to know when this happened. I'm very inexperienced with sagemath, but I know my way around python.
I did this:
g(x) = integrate(f(x), x)
w0 = SR.wild(0)
w1 = SR.wild(1)
s=integrate(w0,w1,hold=True)
if(len(g.find(s)) : print('failed')
else: print('worked')
This worked for my **one** test case, but I'd like to know if this is correct and somewhat general, and also, it looked a bit convoluted to me. There probably is a better solution that I could not find.
Apologies if the above is too gross to contemplate!Fri, 08 Mar 2019 13:46:43 -0600http://ask.sagemath.org/question/45729/how-can-i-detect-failure-of-analytical-integration/Answer by FrédéricC for <p>I want to check whether an analytical integration worked, and to try numerical integration in case it failed. I'd like to know when this happened. I'm very inexperienced with sagemath, but I know my way around python.</p>
<p>I did this:</p>
<pre><code>g(x) = integrate(f(x), x)
w0 = SR.wild(0)
w1 = SR.wild(1)
s=integrate(w0,w1,hold=True)
if(len(g.find(s)) : print('failed')
else: print('worked')
</code></pre>
<p>This worked for my <strong>one</strong> test case, but I'd like to know if this is correct and somewhat general, and also, it looked a bit convoluted to me. There probably is a better solution that I could not find. </p>
<p>Apologies if the above is too gross to contemplate!</p>
http://ask.sagemath.org/question/45729/how-can-i-detect-failure-of-analytical-integration/?answer=45741#post-id-45741Like this
sage: from sage.symbolic.integration.integral import DefiniteIntegral
sage: T=integrate(x,x,0,4,hold=True)
sage: isinstance(T.operator(),DefiniteIntegral)
True
sage: T=integrate(x,x,0,4)
sage: isinstance(T.operator(),DefiniteIntegral)
False
Sat, 09 Mar 2019 12:21:36 -0600http://ask.sagemath.org/question/45729/how-can-i-detect-failure-of-analytical-integration/?answer=45741#post-id-45741Comment by rbw for <p>Like this</p>
<pre><code>sage: from sage.symbolic.integration.integral import DefiniteIntegral
sage: T=integrate(x,x,0,4,hold=True)
sage: isinstance(T.operator(),DefiniteIntegral)
True
sage: T=integrate(x,x,0,4)
sage: isinstance(T.operator(),DefiniteIntegral)
False
</code></pre>
http://ask.sagemath.org/question/45729/how-can-i-detect-failure-of-analytical-integration/?comment=45773#post-id-45773Ouch, this is so much better it hurts...
Many thanks!Tue, 12 Mar 2019 17:30:13 -0500http://ask.sagemath.org/question/45729/how-can-i-detect-failure-of-analytical-integration/?comment=45773#post-id-45773