F Integration By Weddle's Rule | CodeTheta

Integration By Weddle's Rule

January 09, 2014

/******************************************
Integration Ry Weddle's Rule
******************************************/
/* http://native-code.blogspot.com */
#include <conio.h>
#include <math.h>
#include <stdio.h>
#define f(x) (exp(-pow(x, 2)))
void main() {
float a, b, h;
float s, s0, s1, s2, s3, s4;
int i, n;
s = s0 = s1 = s2 = s3 = s4 = 0.0F;
clrscr();
//--------------------------
printf("\nEnter the limits:");
scanf("%f %f", &a, &b);
printf("\nEnter the number of subintervals.(Multiples of 6):");
scanf("%d", &n);
h = (b - a) / n;
//--------------------------
s0 = (f(a) + f(b));
for (i = 1; i <= n - 1; i = i + 6)
s1 += 5 * (f(a + i * h) + f(a + (i + 4) * h));
for (i = 3; i <= n - 3; i = i + 6) s2 += 6 * (f(a + i * h));
for (i = 2; i <= n - 2; i = i + 6) s3 += (f(a + i * h) + f(a + (i + 2) * h));
for (i = 6; i <= n - 6; i = i + 6) s4 += 2 * (f(a + i * h));
//--------------------------
s = ((3 * h) / 10) * (s0 + s1 + s2 + s3 + s4);
printf("\n\n\nRESULT BY WEDDLE'S RULE:%f", s);
getch();
} // end of main
/* http://native-code.blogspot.com */

Post a Comment