在下面的测试中,我希望对每个freq步骤在a和b之间进行集成。我需要提取数组中的数据,以便显示每个freq步骤的集成结果。最后,我想重现一个复杂的积分,在这里,我将绘制真实的和想象的part.Since,我没有相同的变量维,我得到一个广播错误。我不知道怎么用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发布于 2022-09-28 23:34:45
我建议您在集成之前先绘制函数。
这个Wolfram的阴谋,如果正确的话,表明这个函数是单数的。这种集成会有问题。
https://stackoverflow.com/questions/73888810
复制相似问题