Integrating over an interpolate function (interp1d) in python -
i trying double integration on interpolated function, in r = r(x,y).
from scipy import interpolate import scipy sp r = [0, 1, 2] z = [0, 1, 2] def cartesian(x, y, f): r = sp.sqrt(x**2 + y**2) return f(r) interp = interpolate.interp1d(r, z) print(cart(1,1,interp)) = sp.integrate.dblquad(cart, 0, 1, lambda x: 0, lambda x: 1, args=(interp)) print(a) executing cartesian function once produces correct answer. integral gives the following error:
typeerror: integrate() argument after * must iterable, not interp1d i don't understand why function isn't iterable , not know how convert iterable form. many help.
args supposed sequence of arguments, so:
sp.integrate.dblquad(cart, 0, 1, lambda x: 0, lambda x: 1, args=(interp,)) the comma after interp critical: in python, (x) x, (x,) tuple (i.e. sequence).
Comments
Post a Comment