Ask Your Question

How can I detect failure of analytical integration?

asked 2019-03-08 20:46:43 +0200

rbw gravatar image

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)
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!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-03-09 19:21:36 +0200

FrédéricC gravatar image

Like this

sage: from sage.symbolic.integration.integral import DefiniteIntegral
sage: T=integrate(x,x,0,4,hold=True)
sage: isinstance(T.operator(),DefiniteIntegral)
sage: T=integrate(x,x,0,4)
sage: isinstance(T.operator(),DefiniteIntegral)
edit flag offensive delete link more


Ouch, this is so much better it hurts...

Many thanks!

rbw gravatar imagerbw ( 2019-03-12 23:30:13 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-03-08 20:46:43 +0200

Seen: 419 times

Last updated: Mar 09 '19