-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpsons.c
More file actions
44 lines (34 loc) · 850 Bytes
/
simpsons.c
File metadata and controls
44 lines (34 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 1000
double f(double );
int main(){
double sum1,sum2,x[N],h,I;
printf("enter the domain : \n");
scanf("%f %f",&x[0],&x[N-1]);
h = (x[N-1] - x[0])/N;
printf("%f \n",h); // debug
printf("%f \n",f(x[N-1])); // debug
printf("%f \n",f(x[0])); // debug
// h = 0.001;
sum1 = 0;
sum2 = 0;
for (int i = 1; i <= N-2; i = i+2)
{
sum1 += f(x[0]+(i*h));
}
for (int i = 2; i <= N-3; i = i+2)
{
sum2 += f(x[0]+(i*h));
}
printf("%f \n",sum1); // debug
I = (h*0.333333334)*(f(x[0])+f(x[N-1]))+((2*sum1))*h*(0.666666667) + (2*sum2)*(h*0.3333333334);
printf("This is the integral : %f\n",I);
return 0;
}
double f(double x){
return x*x;
//return sin(x);
//return sin(x);
}