Pingk
Pingk

Reputation: 542

Python integrate.quad(1/function) error

I have the following existing code:

integrate.quad(somefunc, lowerbound, upperbound)

However I want to change this to

integrate.quad(1/somefunc, lowerbound, upperbound)

but I get operand errors. Is there a way I can do this without changing somefunc?

Upvotes: 1

Views: 112

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798556

You want to use a lambda to call the function appropriately, similar to so:

integrate.quad(lambda x: 1/somefunc(x), lowerbound, upperbound)

Upvotes: 1

Related Questions