Your task is to write a function that compute a definite int
Solution
Simply if you need a c related function you can go with the following code-
double definateintegral(double(*g)(double y), double a, double b, int m)
{
double width = (b - a ) / m;
double calculatearea = 0.0;
for (int j = 0; j < m; j ++) {
calculatedarea += f(a + (j + 0.5) * width) * width;
}
return area;
}
int main()
{
cout.precision(8);
cout << integral(sin, 0, M_PI / 4, 12);
return 0;
}
Basically if you considered genral algorithm you can use
Step a Set z = (b - a)/n.
Step b Set YJ 0 = f(a) + f(b);
YI 1 = 0; (Summation of f(y2j-1).)
YJ 2 = O. (Summation of f (Y2j)\')
Step c For j = 1, ... ,n - 1 do Steps d and e.
Step d Set Y = a + jz.
Step e when j is even then set YI2 = YI2 + f(Y)
else set YJl = YJl + f(Y).
Step f Set YJ = h(YJO + 2· YJ2 + 4· YJl)/3.
Step g OUTPUT (Yl);
STOP.
