-
Notifications
You must be signed in to change notification settings - Fork 0
/
q_test.c
46 lines (40 loc) · 933 Bytes
/
q_test.c
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
45
46
#include<stdio.h>
#include<math.h>
double qtrap(double (*func)(double, void *), double, double, int, void *);
double qsimp(double (*func)(double, void *), double, double, int, void *);
double my_func(double, void *);
int main()
{
FILE *fptr;
int N=2;
int N_max=5000;
int i;
double out_trap;
double out_simp;
double err_trap;
double err_simp;
double exact;
double a;
double b;
void *params;
fptr = fopen("quadratures.dat","w");
a=0.0;
b=3.0;
params = NULL;
exact = exp(b) - exp(a);
fprintf(fptr,"#N\texact\ttrap\tsimp\terr_trap\terr_simp\n");
for(i=3;i<N_max;i+=2)
{
out_trap=qtrap(&my_func, a, b, i, params);
out_simp=qsimp(&my_func, a, b, i, params);
err_trap=(out_trap-exact)/exact;
err_simp=(out_simp-exact)/exact;
fprintf(fptr,"%d\t%e\t%e\t%e\t%e\t%e\n",i,exact,out_trap,out_simp,err_trap,err_simp);
}
fclose(fptr);
return 0;
}
double my_func(double x, void *params)
{
return exp(x);
}