Integration of a complex function having singularities using quad - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Integration of a complex function having singularities using quad (/thread-18437.html) Integration of a complex function having singularities using quad - amjad26 - May-17-2019 Hi In fact I want to visualize a function using python, but the function unfortunately includes singularities (one in it's end points and the other inside the boundary). first we need to integrate the function f below from -1 to 1. def f(u,t,x=l): q=u**2-x**2 if q<0: q=-q v=complex(0,q) else: v=np.sqrt(u**2-x**2) return(((1-u**2)/(u+v)**3)then divide the integral of f by the integral of function f1. def f1(u,t,x=l): q=u**2-x**2 if q<0: q=-q v=complex(0,q) else: v=np.sqrt(u**2-x**2) return((u)*u*(1-((u-np.sqrt(v))/(u+np.sqrt(u**2+x**2)))**2))Note:v is complex when q<0 to avoid negative number inside the square root. We want to visualize the function that is the (integral of -1 to 1 of f divided by the integral of -1 t0 1 of f1 )times (4x**2) interms of x.(0 s=(complex_quadrature(f,-1,0)+complex_quadrature2(f,0,1))/(complex_quadrature(f1,-1,0)+complex_quadrature2(f1,0,1)) File "untitled11.py", line 27, in complex_quadrature real_integral=quad(real_func,a,b, weight='cauchy', wvar=-1) File "C:\Users\AGT-CR\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\integrate\quadpack.py", line 427, in quad raise ValueError(msg) ValueError: Parameter 'wvar' must not equal integration limits 'a' or 'b'.I tried also to make the endpoints be so close to 0 or 1 but their having their exact values. s=(complex_quadrature(f,-0.9999,-0.0001)+complex_quadrature2(f,0.0001,1))/(complex_quadrature(f1,-0.9999.,-0.0001)+complex_quadrature2(f1,0.0001,1)) but I will also get that error: untitled11.py:21: RuntimeWarning: divide by zero encountered in double_scalars return((u-t)*(1-u**2)/(u+v)**3) untitled11.py:27: IntegrationWarning: Extremely bad integrand behavior occurs at some points of the integration interval. real_integral=quad(real_func,a,b, weight='cauchy', wvar=-1) untitled11.py:47: RuntimeWarning: divide by zero encountered in double_scalars return((u-t)*u*(1-((u-np.sqrt(v))/(u+np.sqrt(u**2+x**2)))**2)) C:\Users\AGT-CR\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\numeric.py:538: ComplexWarning: Casting complex values to real discards the imaginary part return array(a, dtype, copy=False, order=order)`So is there a way to handle such singularities? have I missed singular points other than 0 or -1? Any help is really appreciated.