Prev: cell
Next: estimating 2 parameters, simultaneous odes
From: nuclph nuclph on 12 May 2010 15:20 thank you John, let me look into this. "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hsd4e7$mi2$1(a)fred.mathworks.com>... > "nuclph nuclph" <bskorodo(a)gmail.com> wrote in message <hsd1eg$gi3$1(a)fred.mathworks.com>... > > hi all, > > > > i was looking into matlab help and did not find the answer for my question. > > > > I have vector y {y1, y2, ..yn} defined on set of points {x1,x2, ..xn} not equally spaced. I would like to calculate integral of y from arbitrary a to arbitrary b. What possibilities I have within matlab to do it ? I see there is a quad function but it require to know functional form of y. I do not have that. There is a trapz but the same issue. > > trapz does not require a functional form. However, if > you have arbitrary end points for the integration > relative to your data, then trapz is not directly usable. > > The splines toolbox does allow you to integrate a > spline fit by that TB. Alternatively, you can fit a spline > using my SLM tools on the file exchange. Then slmeval > can do the integration over any interval. > > http://www.mathworks.com/matlabcentral/fileexchange/24443 > > HTH, > John
From: Walter Roberson on 12 May 2010 17:35
nuclph nuclph wrote: > I have step function with jumps at vector x as > defined above. Values of y is also defined at xi points. In between, in > each shoulder y is constant. What i basically want to have is a way to > get integral of y for arbitrary interval [a,b]. if it happens that [a,b] > within shoulder then the integral give just value of y on this shoulder. Now I am confused: if y is constant over the interval [a,b], then surely the integral with respect to that interval is that constant times the width of the interval ?? > If [a,b] happens to contain two shoulders then i need to calc integral > as int_{x(i)} ^ {x(i+1)} (ydx) where y would have only two different > values. I can assume that a,b is always defined within x1 ...xn points. Could you clarify your integral notation? It appears that you are asking to take the first to the power of the second? Or is that an xor? Or something else? You could use histc in order to determine which of the xi the last one up to or including a (you can do b at the same time if you use one of the multiple-output forms of histc). Then, (x{ia+1}-a) * y{ia} + (b-x{ib}) * y{ib} plus the pre-calculated integral from x{ia+1} to x{ib} would give you the distance. Precomputed: cumsum(diff(x) .* y(1:end-1)) and then the integral from x{J} to x{K} is that sum indexed at K minus that sum indexed at J. |