'How to print out complex number as result of scipy integration
I'm learing about numerical methods of computing integrals in python and while exploring, I've met problem with this code:
def f(x):
return (1/((math.cos(x))**x+x**x**x+1));
(quad(f, 0, 2))
the result of this integral seems to be complex and when I run this code, the following error pops out
TypeError Traceback (most recent call last)
<ipython-input-68-afbfde96f37c> in <module>
1 def f(x):
2 return (1/((math.cos(x))**x+x**x**x+1));
----> 3 complex(quad(f, 0, 2))
/usr/lib/python3/dist-packages/scipy/integrate/quadpack.py in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
349
350 if weight is None:
--> 351 retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
352 points)
353 else:
/usr/lib/python3/dist-packages/scipy/integrate/quadpack.py in _quad(func, a, b, args, full_output, epsabs, epsrel, limit, points)
461 if points is None:
462 if infbounds == 0:
--> 463 return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
464 else:
465 return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
TypeError: can't convert complex to float
I would like to get the result as complex number. Any suggestions how to do it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
