module - Integral function (x,y) in python -
i have function like:
(np.sqrt((x)**2 + (y)**2))/(np.sqrt((x)**2 + (y)**2 + d**2))
i wrote program calculating integral using series:
for in range (num): # x print y=(-distance) j in range(num): # y f=(np.sqrt((x)**2 + (y)**2))/(np.sqrt((x)**2 + (y)**2 + d**2)) y=y+delta sum+=(f*(delta**2))/((2*distance)**2) x=x+delta print sum
and works fine me.. takes long complex function.
is there python module integrating function when -2.0 < x
, y < 2.0
? (or else)
i guess want integrate fun
between x
equals a
, b
, y
equals c
, d
. in case have is:
import numpy np # define 'd' whatever value need d = 1. # function integrate fun = lambda x, y: np.sqrt(x**2. + y**2.) / np.sqrt(x**2. + y**2. + d**2.) # limits of integration a, b = -2., 2. c, d = -2., 2. gfun = lambda x: c hfun = lambda x: d # perform integration scipy.integrate import dblquad int, err = dblquad(fun, a, b, gfun, hfun)
if need more complex limits of integration need change gfun
, hfun
. if interested in more advanced feature can take @ documentation of dblquad
: http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.dblquad.html#scipy.integrate.dblquad
Comments
Post a Comment