Prev: cell
Next: estimating 2 parameters, simultaneous odes
From: nuclph nuclph on 11 May 2010 21:49 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. thank you for suggestions.
From: us on 11 May 2010 22:08 "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. > > thank you for suggestions. a hint: help trapz; % <- and siblings... us
From: John D'Errico on 11 May 2010 22:40 "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 11 May 2010 23:34 nuclph nuclph wrote: > 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. quad and trapz are only suitable for approximate integration with it being presumed that the integral is continuous and doesn't vary too much from linear. Your question, though, was phrased in terms of integration, not in terms of an approximate integration for which you are willing to assume that those conditions hold. Your question could be interpreted as indicating that the integral is linear between the given points, but has piecewise discontinuities in the slope at the given points. Could you clarify whether the set of points defines the boundaries, or if the set of points is a *sampling* of a continuous and reasonably-well-behaved formula ?
From: nuclph nuclph on 12 May 2010 15:18
Hi Walter, Than you for comment. 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. 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. Since I am not that familiar with matlab, I was trying to get advice on this forum what is the better way to do in within matlab. In principle, y can be some linear function between nodes xi. It would be nice to have generic way to calc that integral between [a,b] Thank you in advance! Walter Roberson <roberson(a)hushmail.com> wrote in message <TkpGn.2335$rU6.2153(a)newsfe10.iad>... > nuclph nuclph wrote: > > > 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. > > quad and trapz are only suitable for approximate integration with it > being presumed that the integral is continuous and doesn't vary too much > from linear. > > Your question, though, was phrased in terms of integration, not in terms > of an approximate integration for which you are willing to assume that > those conditions hold. Your question could be interpreted as indicating > that the integral is linear between the given points, but has piecewise > discontinuities in the slope at the given points. > > Could you clarify whether the set of points defines the boundaries, or > if the set of points is a *sampling* of a continuous and > reasonably-well-behaved formula ? |