首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python中的2变量数值积分

python中的2变量数值积分
EN

Stack Overflow用户
提问于 2022-09-28 23:29:24
回答 1查看 136关注 0票数 0

在下面的测试中,我希望对每个freq步骤在a和b之间进行集成。我需要提取数组中的数据,以便显示每个freq步骤的集成结果。最后,我想重现一个复杂的积分,在这里,我将绘制真实的和想象的part.Since,我没有相同的变量维,我得到一个广播错误。我不知道怎么用numpy来写这篇文章。

代码语言:javascript
复制
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,)
代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2022-09-28 23:34:45

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

这个Wolfram的阴谋,如果正确的话,表明这个函数是单数的。这种集成会有问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73888810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档