开发者

How do I do numerical integration of a vector in MATLAB?

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 tra开发者_JAVA技巧pz or quad, but i don't really understand how to integrate without the function.


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,

x=0:pi/357:pi;
y=sin(x);
area=trapz(x,y);

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:

area=pi/357*trapz(y);


You don't need to know the function in order to numerically integrate; that's the point of trapz and quad. Just pass trapz your vector. Here's a link to the documentation.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜