【问题标题】:How to calculate the integral from the square of defined function in Python?如何从 Python 中定义函数的平方计算积分?
【发布时间】:2020-10-13 09:23:38
【问题描述】:

我在 Python 中计算积分时遇到问题。

所以,我已经定义了函数:

def function_f(x):
    if x>=0 and x<=1: 
        return ((1/3)**x)
    else:
        return 0

我知道用这个代码计算简单的(没有平方):

from scipy import integrate
integrate.quad((function_f), 0, 1)

但问题是我需要从这个函数的平方计算积分,所以我需要从 (function_f)^2 获得积分。

希望您对我如何做到这一点有一些建议。

【问题讨论】:

    标签: python python-3.x function integral


    【解决方案1】:

    我不习惯 scipy.integrate,但根据您的解释,您应该能够做到:

    integrate.quad(lambda x:function_f(x)**2, 0, 1)
    

    【讨论】:

    • 谢谢,它成功了 :) 你知道我如何从复函数计算积分吗?
    • @Minimalist 哪个复杂函数?
    猜你喜欢
    • 2014-10-24
    • 2020-10-20
    • 1970-01-01
    • 2023-03-11
    • 2014-09-07
    • 2019-12-04
    • 2014-01-04
    • 1970-01-01
    相关资源
    最近更新 更多