##### Integration of a complex function having singularities using quad
 Integration of a complex function having singularities using quad amjad26 Unladen Swallow Posts: 1 Threads: 1 Joined: May 2019 Reputation: May-17-2019, 09:16 PM 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. Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Integration of apache spark and Kafka on eclipse pyspark aupres 1 998 Feb-27-2021, 08:38 AM Last Post: Serafim Tableau Time Series Prediction using Python Integration tobimarsh43 0 666 Jul-24-2020, 10:38 AM Last Post: tobimarsh43 R-PYTHON INTEGRATION RELATED PROBLEM arnab93 0 594 Jun-05-2020, 02:07 PM Last Post: arnab93 STATA/Python Integration jprender 0 656 May-03-2020, 09:38 PM Last Post: jprender phython language java integration jammytcs123123 1 1,232 Jul-04-2018, 03:13 AM Last Post: Skaperen SQLite DB integration duplicate columns rachitmishra25 1 3,521 Oct-27-2017, 11:20 AM Last Post: buran Trapezoidal integration method in python. Getting wrong results auting82 5 3,692 Oct-14-2017, 07:38 PM Last Post: buran Sympy Integration Flexico 5 4,806 Dec-07-2016, 07:24 AM Last Post: micseydel

Forum Jump:

### User Panel Messages ##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020