2

I'd like to calculate an integral of the form

where I want the results as an array (to eventually plot them as a function of omega). I have

    import numpy as np
    import pylab as plt
    from scipy import integrate
    
    w = np.linspace(-5, 5, 1000)

    def g(x):
        return np.exp(-2*x)

    def complexexponential(x, w):
        return np.exp(-1j*w*x)

    def integrand(x, w):
        return g(x)*complexexponential(x, w)

    integrated = np.real(integrate.quad(integrand, 0, np.inf, args = (w)))

which gives me the error "supplied function does not return a valid float". I am not very familiar with the integrate-function of Scipy. Many thanks for your help in advance!

1 Answer 1

1

Scipy integrate.quad doesn't seem to support vector output. If you loop over all your values of w and only give one of them at a time as args your code seems to work fine.

Also it doesn't handle complex integration, which you can get around using the procedure outlined in this answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.