简体   繁体   English

在python中集成多个函数错误

[英]Integrating more than one function error in python

Lets say i define my function G, 假设我定义了我的函数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. 其中P和W是两个具有独立变量k的函数,并且k是定义的数。

I am trying to integrate this from 0 to infinity 我正在尝试将其从0集成到无穷大

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

inputting this into my console gives me the error, G() takes exactly 3 arguments (2 given) 将其输入到控制台会给我错误, 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. 我尝试使用arg()命令,但是它似乎并没有改变它,并且代码仍然很固执。 What am i doing wrong and what am i missing? 我做错了什么,我想念什么?

If I understand correctly, k is a constant. 如果我理解正确,则k是一个常数。 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 . scipy文档中找到它。

Besides, your integral looks divergent. 此外,您的积分外观也有所不同。

For symbolic integrals see sympy.integrate . 有关符号积分,请参见sympy.integrate It is a different library. 这是一个不同的库。

import * from sympy

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM