File: integral-test.c

package info (click to toggle)
insighttoolkit 3.18.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 110,432 kB
  • ctags: 74,559
  • sloc: cpp: 412,627; ansic: 196,210; fortran: 28,000; python: 3,852; tcl: 2,005; sh: 1,186; java: 583; makefile: 458; csh: 220; perl: 193; xml: 20
file content (56 lines) | stat: -rw-r--r-- 1,105 bytes parent folder | download | duplicates (12)
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
47
48
49
50
51
52
53
54
55
56
#include "v3p_netlib.h"

#include <stdio.h>

double f(double *x)
{
  return (*x)/(1+(*x)*(*x));
}

void test_simpson_integral()
{
  double a = 0;
  double b = 1;
  double res;
  long n = 100;

  v3p_netlib_simpru_(&f, &a, &b, &n, &res);
  printf("simpson integral of x/(1+x^2) from 0 to 1 (%ld grids) is %2.10f\n", n, res);
}

void test_adapted_simpson_integral()
{
  double a = 0;
  double b = 1;
  double res;
  long n = 100;
  double rmat[1111];
  double tol = 1e-10;
  double errbound;
  long stat;

  v3p_netlib_adaptquad_(&f, &a, &b, &tol, rmat, &res, &errbound, &n, &stat);
  printf("adapted simpson integral (with tol=%g) of x/(1+x^2) from 0 to 1 (%ld grids) is %2.10f\n", tol, n,  res);
  printf("errbound is %f, state is %ld\n", errbound,  stat);
}

void test_trapezod_integral()
{
  double a = 0;
  double b = 1;
  double res;
  long n = 500;

  v3p_netlib_trapru_(&f, &a, &b, &n, &res);
  printf("trapezod integral of x/(1+x^2) from 0 to 1 (%ld grids) is %f\n", n, res);
}



int main()
{
  test_simpson_integral();
  test_adapted_simpson_integral();
  test_trapezod_integral();
  return 0;
}