| 1 | initial version |
Can you use a try/except block?
sage: def check_convergence(exp):
....: try:
....: print sum(exp,x,1,oo)
....: except:
....: print "Oops!"
....:
sage: check_convergence(1/x^2)
1/6*pi^2
sage: check_convergence(1/x)
#0: simplify_sum(expr='sum(1/x,x,1,inf))
Oops!
I can't seem to get rid of that extra #0 thingie. Maxima sometimes prints out extra stuff now with our ECL library interface.
| 2 | No.2 Revision |
Can you use a try/except block?
sage: def check_convergence(exp):
....: try:
....: print sum(exp,x,1,oo)
....: except:
....: except ValueError, msg:
if 'divergent' in str(msg):
print "Oops!"
....: "Diverges!"
else:
raise ValueError, msg
Then
sage: check_convergence(1/x^2)
1/6*pi^2
sage: check_convergence(1/x)
#0: simplify_sum(expr='sum(1/x,x,1,inf))
Oops!
I can't seem to get rid of that extra #0 thingie. Maxima sometimes prints out extra stuff now with our ECL library interface.
Notice also
sage: check_convergence(1/22)
+Infinity
because Maxima doesn't use the word diverge there, but evaluates it to infinity. Strange...
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.