Numerical integration over non-uniform grid in matlab. Is there any function?
math, matlab
Solution
Taken from help :
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.
As you can see `x` does not have to be uniform.
For instance:
x = sort(rand(100,1)); %# Create random values of x in [0,1]
y = x;
trapz( x, y)
Returns:
ans =
0.4990
Another example:
x = sort(rand(100,1)); %# Create random values of x in [0,1]
y = x.^2;
trapz( x, y)
returns:
ans =
0.3030
Problem
I've got function values in a vector `f` and also the vector containing values of the argument `x`. I need to find the define integral value of `f`. But the argument vector `x` is not uniform. Is there any function in Matlab that deals with integration over non-uniform grids?