开发者

How do I integrate a curve numerically in MATLAB? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

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

I have an x-y dataset (see figure) but I don't have the fundamental function of the data, so I can't use symbolic integration. Is there an easy way to integrate the curve numerically?

The only way I can think of is a for loop over evey y-value times the delta x betw开发者_如何学JAVAeen two points next to each other? Are there other ways to do it?

How do I integrate a curve numerically in MATLAB? [duplicate]


trapz is probably what you are looking for:

TRAPZ Trapezoidal numerical integration.

Z = TRAPZ(X,Y) computes the integral of Y with respect to X using
the trapezoidal method.  X and Y must be vectors of the same
length, or X must be a column vector and Y an array whose first
non-singleton dimension is length(X).  TRAPZ operates along this
dimension.


You should be looking at an integration scheme like Runge-Kutta or Burlish-Stoer. You'll want something that uses a variable increment so you can use a larger step where the function is flat and a smaller one to capture those peaks.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜