public
Description: Perl interface to the GNU Scientific Library
Homepage: http://leto.net/code/Math-GSL
Clone URL: git://github.com/leto/math--gsl.git
Click here to lend your support to: math--gsl and make a donation at www.pledgie.com !
math--gsl / examples / sf / erfc_check
100755 36 lines (29 sloc) 1.038 kb
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
#!/usr/bin/perl
# interfc
# v0.2 Keith Lofstrom 2008 Sept 18
# with tweaks by Jonathan Leto
#
# Compare the results of numerical integration of
# (2.0/sqrt(PI)*integral[x,inf](e^(-x^2) ) with the
# erfc() function.
#
# The results are pretty good, within 1e-14 or better
# for the examples tried
 
use Math::GSL::SF qw/:all/;
use Math::GSL::Integration qw/:all/;
use Math::GSL::Const qw/:all/;
use strict;
 
my $workspace = gsl_integration_workspace_alloc(101);
my $maxdiff = 0;
 
printf " arg erfc int() difference\n";
 
for( my $i=-5.2 ; $i<=5.201 ; $i += 0.1 ) {
   my $e = gsl_sf_erfc($i);
   my ($status, $result, $abserr ) = gsl_integration_qagiu(
                     sub { exp( -($_[0]**2) ) },
                     $i, 0, 1e-9, 100, $workspace );
 
   my $yy = $M_2_SQRTPI * $result ;
   my $diff=$yy-$e ;
   $maxdiff = abs($diff) > $maxdiff ? abs($diff) : $maxdiff;
 
   printf "%4.1f%18.12f%18.12f %.18g\n", $i, $e, $yy, $diff ;
}
printf "Maximum local error: %.12g\n", $maxdiff;