In an isympy
session:
In [1]: from sympy.abc import x, i
In [2]: f=lambda y, t: (5*exp(-y**2) - 5 * exp(-y**2) * exp(-10/(1+x**2))) * exp
...: (i*x*t) * exp(-i*y*t) / (1 - exp(-10/1+t**2))
In [3]: f
Out[3]: <function __main__.<lambda>(y, t)>
dblquad
is going to call this function with specific values of y
and t
- ones within the bounds. So let's test such a call:
In [4]: f(0,0)
Out[4]:
-10
──────
2
x + 1
5.00022700995505 - 5.00022700995505⋅ℯ
The result is a sympy expression, with symbol x
, and sympy
exp
.
dblquad
is a numeric integrator; it expects numbers, not expressions. So it "asks" for that float
- but sympy
says - " can't do that". That's the TypeError
.
In [5]: float(f(0,0))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 float(f(0,0))
File /usr/local/lib/python3.8/dist-packages/sympy/core/expr.py:345, in Expr.__float__(self)
343 if result.is_number and result.as_real_imag()[1]:
344 raise TypeError("Cannot convert complex to float")
--> 345 raise TypeError("Cannot convert expression to float")
TypeError: Cannot convert expression to float
In short, you get the TypeError because you are trying to use a sympy expression in a numeric integrator.