summaryrefslogtreecommitdiff
path: root/gsl-1.9/doc/examples/integration.c
diff options
context:
space:
mode:
Diffstat (limited to 'gsl-1.9/doc/examples/integration.c')
-rw-r--r--gsl-1.9/doc/examples/integration.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gsl-1.9/doc/examples/integration.c b/gsl-1.9/doc/examples/integration.c
new file mode 100644
index 0000000..a8f2450
--- /dev/null
+++ b/gsl-1.9/doc/examples/integration.c
@@ -0,0 +1,37 @@
+#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 = &alpha;
+
+ gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000,
+ w, &result, &error);
+
+ 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;
+}