【问题标题】:numerical integration of complex integral in pythonpython中复积分的数值积分
【发布时间】:2022-10-05 06:31:44
【问题描述】:

在下面的测试中,我想为每个频率步骤在 a 和 b 之间进行积分。我需要提取数组中的数据,以便显示每个频率步骤的积分结果。最终我想为一个复杂的积分重现它,我将在其中绘制实部和虚部。因为我没有相同的变量尺寸,所以我得到一个广播错误。我不确定如何仅使用 numpy 来编写这篇文章。

f = np.sin(x)*freq  # for each freq calculate the integrale and store the result 
ValueError: operands could not be broadcast together with shapes (11,) (5,)
import numpy as np
a = 0
b = 10
n = 11
h = (b - a) / (n - 1)
x = np.linspace(a, b, n)
freq = np.linspace(0.001, 100, 5)

f = np.exp(x*freq)  # for each freq calculate the integrale and store the result of whatever function of 2 variables

#integration
for f in freq:
    I_simp = ((h/3) * (f[x[0],freq[0]] + 2*sum(f[x[:n-2:2],freq[f]]) \
                + 4*sum(f[x[1:n-1:2],freq[f]]) + f[x[n-1],freq[-1]]))

print(I_simp)    #print the array , in case of complex i will then extract real and imag

【问题讨论】:

    标签: python integration numeric complextype


    【解决方案1】:

    我建议您在集成之前绘制函数。

    这个plot from Wolfram,如果正确的话,表明这个函数是单数的。您将遇到此集成的问题。

    【讨论】:

    • true 但实部和 im 部分随着频率而减少并收敛。我在 python 或 matlab 中使用 MeijerG 函数管理高达 10^10 但不是辛普森规则。
    • 奇异函数通常需要高斯或对数正交。天真的辛普森法则不会是我的选择。
    猜你喜欢
    • 1970-01-01
    • 2017-02-02
    • 2014-07-19
    • 2012-08-12
    • 1970-01-01
    • 2019-07-19
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多