You are on page 1of 3

SIMPSON'S 1/3 RULE

THEORY:

ALGORITHM FOR SIMPSON'S 1/3 RULE:


1. Start
2. Define function f(x)
3. Read lower limit of integration, upper limit of
integration and number of sub interval
4. Calcultae: step size = (upper limit - lower limit)/number of sub interval
5. Set: integration value = f(lower limit) + f(upper limit)
6. Set: i = 1
7. If i > number of sub interval then goto
8. Calculate: k = lower limit + i * h
9. If i mod 2 =0 then
Integration value = Integration Value + 2* f(k)
Otherwise
Integration Value = Integration Value + 4 * f(k)
End If
10. Increment i by 1 i.e. i = i+1 and go to step 7
11. Calculate: Integration value = Integration value * step size/3
12. Display Integration value as required answer
13. Stop

SOURCE CODE:
#include <stdio.h>
#include <math.h>

double func(double x)
{
return 1 / (1 + x * x);
}

int main()
{
int i, n;
double a, b, h, sum = 0, x, y;

printf("Enter the number of subintervals: ");


scanf("%d", &n);
printf("Enter the limits of integration:\n");
scanf("%lf%lf", &a, &b);

h = (b - a) / n;

printf("\nx0 = %lf\t", a);


printf("y0 = %lf\n", func(a));

for (i = 1; i < n; i++) {


x = a + i * h;
y = func(x);
printf("x%d = %lf\t", i, x);
printf("y%d = %lf\n", i, y);
if (i % 2 == 0) {
sum += 2 * y;
} else {
sum += 4 * y;
}
}

x = b;
y = func(b);
printf("x%d = %lf\t", n, x);
printf("y%d = %lf\n", n, y);
sum = (sum + y) * h / 3;
sum += func(a) + func(b);

printf("\nThe definite integral is: %lf\n", sum);

return 0;
}

OUTPUT:

DISCUSSION AND CONCLUSION:

Here, we discussed about the algorithm and source code of Simpson 1/3 Rule and we
practically coded the source code of the of Simpson 1/3 Rule using C programming
language to test the example of solution of a problem relating to of Simpson 1/3 Rule.

You might also like