0

I have been trying to work our my project using a Python code which needs integration within a sigma. I get the following error and despite trying several ways, I was not able to solve it. Below you can find a shorter version of my code for error duplication.

The code can be run without any problem if the lower limit of the integral is zero or positive. If it's negative the code gives error...

  File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\integrate\quadpack.py", line 341, in quad
    points)
  File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\integrate\quadpack.py", line 448, in _quad
    return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
TypeError: must be real number, not mpc
import numpy as np
from scipy.integrate import quad
from mpmath import besselk, besseli, nsum, inf, exp, log, cos, mp
mp.dps = 3; mp.pretty = True

tt = (np.logspace(0.0001, 10, num=10)).round(2)
lenght = len(tt)

k0 = lambda u: besselk(0,u)

f = lambda u: u*exp(-2)
Zwn = lambda n: 0.5*(cos(n)*cos(2*n))
Rn = lambda u, n, xD: (1/u)*k0(xD*((f(u) + (n)**2)**0.5))

Lap_Func = lambda u: nsum(lambda n: ((quad(lambda xD: Zwn(n)*Rn(u, n, xD), -10, 10))[0]), [1, 100])

print(Lap_Func((log(2))*1/tt[3]))
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
Ali Wali
  • 179
  • 2
  • 8

1 Answers1

1

Quad only deals with floats, and does not understand mpmath objects. Either drop mpmath and use directly numpy/scipy functions, or convert mpmath expressions to floats at the end of computations.

ev-br
  • 24,968
  • 9
  • 65
  • 78