smoghe
11-11-2003, 04:49 PM
I have a set of data points (x,y). To find out the area under the curve, I am tyring to use the integration function (qtrap). I know how to use 'qtrap' if I know a function in closed form for e.g. y=x*x. However, given the (x,y) set of points how do I perform intergration ? Is it necessary to do some sort of curve fitting first ?
thank you,
sachin
Taylor
12-07-2003, 06:08 AM
hey,
I have a similar problem. Have you already come up with a good way to do it?
TMcCloskey
12-07-2003, 11:05 AM
Sachin -- If you insist on using "qtrap" then, yes, I would recommend that you include within your function "func" (that "qtrap" passes to "qtrapzd") a means of providing an approximation to f(x) utilizing the discrete information you already have.
This doesn't have to be a complicated approximation - remember, you are already just approximating the integral and integration tends to be a "smoothing" operation anyway.
The core routine of "qtrap" is "trapzd". This routine is going to compute the various ordinate values "x" which it will need your coordinate values "f(x)". I would recommend a local approximation, eg, Lagrange Interpolation using 3 or 4 neighboring points spanning the targeted point "x" that trapzd will ask for to compute an approximation for "f(x)". If you provide this functionality within your function "func", then you can use "qtrap" as is.
But what about computing the approximation directly? If your data is equally spaced, then you can compute the approximation directly by picking the applicable sub-division to correspond with the spacing of your data (you'll have to manually code the routine however).