-
Notifications
You must be signed in to change notification settings - Fork 4
/
gsl.c
executable file
·35 lines (28 loc) · 969 Bytes
/
gsl.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
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_integration.h>
double f (double x, void * params)
{
double alpha = *(double *) params;
double f = log(alpha*x) / sqrt(x);
return f;
}
int main (void)
{
gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);
double result, error;
// double expected = -4.0;
double alpha = 1.0;
gsl_function F;
F.function = &f;
F.params = α
gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000, w, &result, &error);
// int gsl_integration_qags (const gsl function * f, double a, double b, [Function] double epsabs, double epsrel, size t limit, gsl integration workspace * workspace, double * result, double * abserr)
printf ("result = % .18f\n", result);
// printf ("exact result= % .18f\n", expected);
printf ("estimated error = % .18f\n", error);
// printf ("actual error = % .18f\n", result - expected);
// printf ("intervals = %d\n", w->size);
gsl_integration_workspace_free (w);
return 0;
}