如何在 MATLAB 中对向量进行数值积分?
我有一个 358 个数字的向量。我想对这个向量进行数值积分,但我不知道这个向量的功能。
我发现我们可以使用 trapz 或quad,但我真的不明白如何在没有该功能的情况下进行集成。
I have a vector of 358 numbers. I'd like to make a numerical integration of this vector, but I don't know the function of this one.
I found that we can use trapz or quad, but i don't really understand how to integrate without the function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您知道向量的水平间距,则可以在中使用 trapz为了在没有该功能的情况下集成它。例如,要将
y=sin(x)
从 0 到 pi 的 358 个部分积分,如果您只使用
trapz(y)
,您将得到一个更大的数字,因为假设点之间的默认距离为 1。可以通过乘以 x 点之间的距离来解决此问题:If you know the horizontal spacing of your vector, you can use trapz in order to integrate it without the function. For example, to integrate
y=sin(x)
from 0 to pi with 358 sections,If you just use
trapz(y)
, you'll get a much larger number, since the default distance between points is assumed to be 1. This problem can be fixed by multiplying by the distance between x points:您无需了解该函数即可进行数值积分;这就是
trapz
和quad
的要点。只需传递trapz
你的向量即可。这是文档链接。You don't need to know the function in order to numerically integrate; that's the point of
trapz
andquad
. Just passtrapz
your vector. Here's a link to the documentation.将积分视为找到由向量形成的曲线下的面积。嗯,它实际上不是一条曲线,而是多边形链。 TRAPZ 函数正在做什么,它找到每个梯形的面积和由向量中的每两个相邻点及其在 X 轴上的投影组成。如果点之间的距离不均匀或者距离不等于 1,请参阅函数文档。
您可以在 Wikipedia 上阅读有关此方法的更多信息。
Think about integration as to find area under the curve, which is formed by your vector. Well it's not actually a curve, but polygonal chain. What TRAPZ function is doing, it finds sum of areas of each trapezoids formed by every two neighbor points in your vector and their projection on X axis. See the function documentation, if you have uneven distance between your points or if distance not equal one.
You can read more about this method, for example, on Wikipedia.