Alex Rivera | Logout

Integration (math) in C++

Asked 2010-06-05T21:25:11.930
9

I'm looking for a library to find the integral of a given set of random data (rather than a function) in C++ (or C, but preferably C++). There is another question asking about integration in C but the answers discuss more how to integrate a function (I think...). I understand that this can be done simply by calculating the area under the line segment between each pair of points from start to finish, but I'd rather not reinvent the wheel if this has already been done. I apologize in advance if this is a duplicate; I searched pretty extensively to no avail. My math isn't as strong as I'd like it so it's entirely possible I'm using the wrong terminology.

Thanks in advance for any help!

Chris

Edit: In case anybody is interested, I feel like an idiot. Even adding in a bunch of OO abstraction to make my other code easier to use, that was maybe 30 lines of code. This is what 3 years away from any sort of math will do to you...thanks for all of the help!

Edit
Report

1 Answer

14

i have just had my numerical exam today :) and i have 3 rules for you

Trapezoidal rule :

integral = h/2 * ( y0 + 2y1 + 2y2 + 2y3 ....... + yn)

Mid-point rule :

integral = h * ( y0.5 + y1.5 + y2.5 + .... y(n-0.5) )

y0.5 means the value of y at the point between x0 and x1

Simpsons Rule :

integral = h/3 * ( y0 + 4y1 + 2y2 + 4y3 + 2y4 ....... + yn)

where h is the step you take which is usually small number ( but not too small to avoid round off error) and n is the number of periods you take

those were the easy to apply ... you can read more about gauss quadrature also

references :

answered 2010-06-05T21:49:18.803

Your Answer