Implement the trapezoidal rule for integrating a function


Implement the Trapezoidal Rule for integrating a function. Use the following function:

double trap(double (*pf)(double x), double a, double b, int n) Here, pf points to the function f that is to be integrated, a and b bracket the interval [a, b] over which f is to be integrated, and n is the number of subintervals to use. For example, the call trap(square,1,2,100) would return 1.41421. The Trapezoidal Rule returns the sum of the areas of the n trapezoids that would approximate the area under the graph of f. For example, if n = 5, then it would return the following, where h = (b-a)/5, the width of each trapezoid.

h---[ f( a) + 2f(a + h ) + 2f(a + 2h ) + 2f(a + 3h ) + 2f( a + 4h) + f(b )] 2.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Implement the trapezoidal rule for integrating a function
Reference No:- TGS01186330

Now Priced at $5 (50% Discount)

Recommended (98%)

Rated (4.3/5)