How do I integrate a curve numerically in MATLAB? [duplicate]
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?
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.
精彩评论