ValveTime.co.uk | Valve News, Forums, Steam

anybody handy with programming feel like tossing together a program to do reiman sums of Simpson's rule and trapezoid rule approximations quickly.

Basically you have some function f(x) that you want to integrate between a and b. So you break that into n equal length subintervals of length h and you have n+1 values for x and f(x). x0 x1 x2... xn. h=(b-a)/n

For the Simpson's approximation, the total area is
h/3[f(x0)+4f(x1)+2f(x2)+4f(x3)+...+2f(xn-2)+4f(xn-1)+f(xn)]

the pattern is just 1 4 2 4 2... 2 4 2 4 1

For the trapezoid approximation, the total area is
h/2[f(x0)+2f(x1)+2f(x2)+...+2f(xn-2)+2f(xn-1)+2f(xn)]

and the pattern there is 1 2 2 2... 2 2 2 1

So the input variables are f(x), n, a, b, and which approximation it uses, and the output is the approximated integral.
As you can probably guess it takes ****ing forever to add up by hand.
Back
Top