Numerical integration trapz for certain interval

35 views (last 30 days)
Hello,
I have some data
rA = [-0.2 -0.0167 -0.00488 -0.00286 -0.00204];
X = [0 0.1 0.4 0.7 0.9];
and I made a plot of rA/60 vs. X.
If I want to numerically integrate this between X = X1 and X = X2, how can I do that? What is important to note is that I don't only want to be bounded by having to do it for the data points. For example, suppose I want to numerically integrate from X = 0.5 to X = 0.6, how might I do that? trapz seems to only let me integrate the whole thing.
I have an equation Volume = integral(dX/rA) from bounds X1 to X2. rA is a function of X, although not well defined. I need to initially solve for X1. How might I make it so that it will integrate until it reaches an X2 such that the integral equates to the known Volume?

Answers (1)

Star Strider
Star Strider on 16 Sep 2014
Edited: Star Strider on 16 Sep 2014
The integration in your first paragraph is relatively straightforward:
Xi = [0.5 0.6]'; % Interpolation X-Values
rAi = interp1(X, rA/60, Xi); % Interpolate
IrA = trapz(rAi, Xi); % Integrate
produces:
IrA =
6.1722e-006
Your second paragraph eludes me. At least one of your integration limits would seem to need to be defined. Otherwise, (assuming the desired volume is less than the integral of the entire function), any arbitrary interval would work for the volume. In the absence of an analytic function of ‘rA’ as a function of ‘X’, integrating it to a known volume would require interp1 over a relatively fine grid, then cumtrapz to approximate the integral over the grid. That is simply an extension of what I did to integrate over ‘Xi’.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!