Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / doc / examples / integration.c
1 #include <stdio.h>
2 #include <math.h>
3 #include <gsl/gsl_integration.h>
4
5 double f (double x, void * params) {
6   double alpha = *(double *) params;
7   double f = log(alpha*x) / sqrt(x);
8   return f;
9 }
10
11 int
12 main (void)
13 {
14   gsl_integration_workspace * w 
15     = gsl_integration_workspace_alloc (1000);
16   
17   double result, error;
18   double expected = -4.0;
19   double alpha = 1.0;
20
21   gsl_function F;
22   F.function = &f;
23   F.params = &alpha;
24
25   gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000,
26                         w, &result, &error); 
27
28   printf ("result          = % .18f\n", result);
29   printf ("exact result    = % .18f\n", expected);
30   printf ("estimated error = % .18f\n", error);
31   printf ("actual error    = % .18f\n", result - expected);
32   printf ("intervals =  %d\n", w->size);
33
34   gsl_integration_workspace_free (w);
35
36   return 0;
37 }