Search code examples
pythonnumpyscipyintegral

How to calculate improper integral in python?


How can I calculate the value of this integral:

enter image description here

f_tu(t) is given as numpy.array. The graph looks like this:

enter image description here

How can I implement this? Everything I could find looks something like this

from scipy.integrate import quad
def f(x):
    return 1/sin(x)
I = quad(f, 0, 1)

but I have an array there, not a specific function like sin.


Solution

  • How about auc from sklearn.metrics?

    import numpy as np
    
    import numpy as np
    
    from scipy.integrate import quad
    
    from sklearn.metrics import auc
    
    x = np.arange(0, 100, 0.001)
    y = np.sin(x)
    
    print('auc:', auc(x,y))
    
    print('quad:', quad(np.sin, 0, 100))
    

    auc: 0.13818791291277366
    quad: (0.1376811277123232, 9.459751315610276e-09)