【问题标题】:Problem with sending argument using dblquad integrator使用 dblquad 积分器发送参数的问题
【发布时间】:2021-05-24 10:08:41
【问题描述】:
from scipy import integrate

def g(y,x,a):
    
    return x*y**2 + a

a= 13

integrate.dblquad(g, 0, 2, lambda x: 0, lambda x: x, args=(a))

TypeError Traceback(最近一次调用最后一次) 在 5个= 13 6 ----> 7 积分.dblquad(g, 0, 2, lambda x: 0, lambda x: x, args=(a))

~\anaconda3\lib\site-packages\scipy\integrate\quadpack.py in dblquad(func, a, b, gfun, hfun, args, epsabs, epsrel) 第599章 600 --> 601 返回 nquad(func, [temp_ranges, [a, b]], args=args, 602 opts={“epsabs”:epsabs,“epsrel”:epsrel}) 603

~\anaconda3\lib\site-packages\scipy\integrate\quadpack.py in nquad(func, range, args, opts, full_output) 824 其他: 825 opts = [opt if callable(opt) else _OptFunc(opt) for opt in opts] --> 826 返回 _NQuad(func, 范围, opts, full_output).integrate(*args) 827 828

TypeError: * 之后的集成()参数必须是可迭代的,而不是 int

【问题讨论】:

  • 使用args=(a,)创建一个1元组

标签: python scipy arguments integrate


【解决方案1】:

您可以在g 内部(甚至外部)定义a

from scipy import integrate

a = 13

def g(y, x):
    return x * y ** 2 + a


integrate.dblquad(g, 0, 2, lambda x: 0, lambda x: x)

(我从来不是 args 争论的大人物。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-04
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多