iron2man
iron2man

Reputation: 1827

Integrating more than one function error in python

Lets say i define my function G,

def G(k, P, W):
    return k**2*P*W**2

Where P and W are two functions that have independent variables of k and k is a defined number.

I am trying to integrate this from 0 to infinity

I = scipy.integrate.quad(G, 0, np.Inf)

inputting this into my console gives me the error, G() takes exactly 3 arguments (2 given)

I tried using the arg() command, but it does not seem to change it and code remains stubborn. What am i doing wrong and what am i missing?

Upvotes: 1

Views: 63

Answers (1)

Tamas Hegedus
Tamas Hegedus

Reputation: 29896

If I understand correctly, k is a constant. Then you can write:

k = 10
I = integrate.dblquad(lambda p,w: G(k,p,w), 0, np.Inf, lambda x: 0, lambda x: np.Inf)

Found it in the scipy documentation.

Besides, your integral looks divergent.

For symbolic integrals see sympy.integrate. It is a different library.

import * from sympy

k,P,W = symbols('k P W')
integrate(G(k,P,W),P,W)

Upvotes: 2

Related Questions