added test for the confluent hypergeometric function 1F1(m,n,z) of the GSL lib
This commit is contained in:
15
src/tests/hypergeometricFcn/README
Normal file
15
src/tests/hypergeometricFcn/README
Normal file
@ -0,0 +1,15 @@
|
||||
hypergeometricFcn is a test to verify that Mathematica and the GSL lib
|
||||
produce the same output for the confluent hypergeometric function 1F1(m,n,z).
|
||||
The file erfi.dat is a file generate by Mathematica with the following commands
|
||||
|
||||
f = Erfi[z]
|
||||
tt = Table[{z, f}, {z, 0, 3, 0.01}]
|
||||
Export["erfi.dat", tt]
|
||||
|
||||
and Erfi[z] can be written in terms of 1F1(m,n,z) as
|
||||
|
||||
Erfi[z] = 2 z / Sqrt[Pi] Hypergeometric1F1[1/2, 3/2, z^2]
|
||||
|
||||
The only thing hypergeometricFcn does is to read erfi.dat, calculate Erfi[z]
|
||||
according to the above equation and save both data sets in a file called
|
||||
erfi_gsl.dat.
|
301
src/tests/hypergeometricFcn/erfi.dat
Normal file
301
src/tests/hypergeometricFcn/erfi.dat
Normal file
@ -0,0 +1,301 @@
|
||||
0 0
|
||||
0.01 0.01128416780862822
|
||||
0.02 0.02257059271413823
|
||||
0.02999999999999999 0.03386153316791828
|
||||
0.04 0.04515925033172434
|
||||
0.05 0.05646600943625297
|
||||
0.05999999999999999 0.06778408114378643
|
||||
0.07 0.07911574291627587
|
||||
0.08 0.09046328039023708
|
||||
0.08999999999999999 0.1018289887598418
|
||||
0.1 0.1132151741695998
|
||||
0.11 0.1246241551180391
|
||||
0.12 0.1360582638738105
|
||||
0.13 0.1475198479056553
|
||||
0.14 0.1590112713276985
|
||||
0.1499999999999999 0.1705349163615497
|
||||
0.16 0.1820931848167174
|
||||
0.17 0.1936884995908712
|
||||
0.1799999999999999 0.2053233061915081
|
||||
0.19 0.2170000742806184
|
||||
0.2 0.2287212992439713
|
||||
0.2099999999999999 0.2404895037866808
|
||||
0.22 0.252307239556747
|
||||
0.23 0.2641770887983099
|
||||
0.2399999999999999 0.2761016660363946
|
||||
0.25 0.288083619794972
|
||||
0.26 0.300125634350208
|
||||
0.27 0.3122304315208248
|
||||
0.28 0.3244007724975507
|
||||
0.2899999999999999 0.3366394597136943
|
||||
0.2999999999999999 0.3489493387589361
|
||||
0.31 0.3613333003384971
|
||||
0.32 0.3737942822799063
|
||||
0.33 0.3863352715896648
|
||||
0.34 0.3989593065621741
|
||||
0.35 0.4116694789433721
|
||||
0.3599999999999999 0.4244689361516121
|
||||
0.37 0.4373608835583889
|
||||
0.38 0.4503485868316228
|
||||
0.39 0.4634353743442958
|
||||
0.4 0.4766246396513396
|
||||
0.41 0.4899198440377719
|
||||
0.4199999999999999 0.5033245191411938
|
||||
0.4299999999999999 0.5168422696518704
|
||||
0.44 0.5304767760937363
|
||||
0.45 0.5442317976897957
|
||||
0.46 0.5581111753155144
|
||||
0.47 0.5721188345439376
|
||||
0.4799999999999999 0.5862587887864184
|
||||
0.4899999999999999 0.6005351425329815
|
||||
0.5 0.614952094696511
|
||||
0.51 0.629513942065115
|
||||
0.52 0.6442250828671904
|
||||
0.53 0.659090020453895
|
||||
0.54 0.6741133671039147
|
||||
0.55 0.6892998479556272
|
||||
0.56 0.7046543050719494
|
||||
0.57 0.7201817016433922
|
||||
0.5799999999999999 0.7358871263350611
|
||||
0.5899999999999999 0.7517757977835818
|
||||
0.5999999999999999 0.7678530692501769
|
||||
0.6099999999999999 0.7841244334363807
|
||||
0.62 0.800595527469159
|
||||
0.63 0.8172721380624627
|
||||
0.64 0.834160206862572
|
||||
0.65 0.8512658359848793
|
||||
0.66 0.8685952937500885
|
||||
0.67 0.8861550206281582
|
||||
0.68 0.9039516353986728
|
||||
0.69 0.9219919415366877
|
||||
0.7 0.9402829338335074
|
||||
0.7099999999999999 0.9588318052622525
|
||||
0.7199999999999999 0.9776459540985063
|
||||
0.7299999999999999 0.9967329913067852
|
||||
0.7399999999999999 1.01610074820405
|
||||
0.75 1.035757284411963
|
||||
0.76 1.055710896110123
|
||||
0.77 1.075970124603062
|
||||
0.78 1.096543765214321
|
||||
0.79 1.117440876521578
|
||||
0.8 1.138670789947371
|
||||
0.81 1.16024311972064
|
||||
0.82 1.182167773225021
|
||||
0.83 1.204454961750493
|
||||
0.8399999999999999 1.227115211665787
|
||||
0.8499999999999999 1.250159376029729
|
||||
0.8599999999999999 1.273598646660546
|
||||
0.87 1.297444566682988
|
||||
0.88 1.321709043574109
|
||||
0.89 1.346404362729431
|
||||
0.9 1.371543201572287
|
||||
0.91 1.397138644230154
|
||||
0.92 1.423204196802919
|
||||
0.93 1.449753803249173
|
||||
0.94 1.476801861917867
|
||||
0.95 1.504363242753928
|
||||
0.9599999999999999 1.532453305207788
|
||||
0.9699999999999999 1.561087916880205
|
||||
0.9799999999999999 1.590283472935232
|
||||
0.9899999999999999 1.620056916315735
|
||||
1. 1.650425758797542
|
||||
1.01 1.681408102919991
|
||||
1.02 1.713022664832454
|
||||
1.03 1.74528879809836
|
||||
1.04 1.778226518500184
|
||||
1.05 1.811856529891002
|
||||
1.06 1.84620025114042
|
||||
1.07 1.881279844224987
|
||||
1.08 1.917118243515681
|
||||
1.09 1.953739186317573
|
||||
1.1 1.991167244719524
|
||||
1.11 2.029427858814586
|
||||
1.12 2.068547371354753
|
||||
1.13 2.108553063906904
|
||||
1.14 2.149473194580001
|
||||
1.15 2.191337037397191
|
||||
1.159999999999999 2.234174923390037
|
||||
1.169999999999999 2.278018283496002
|
||||
1.179999999999999 2.322899693344363
|
||||
1.189999999999999 2.368852920020018
|
||||
1.2 2.415912970899116
|
||||
1.21 2.464116144655226
|
||||
1.22 2.513500084539712
|
||||
1.23 2.564103834045282
|
||||
1.24 2.615967895067185
|
||||
1.25 2.669134288682375
|
||||
1.26 2.723646618673162
|
||||
1.27 2.779550137928277
|
||||
1.28 2.836891817861157
|
||||
1.29 2.895720420992494
|
||||
1.3 2.956086576851622
|
||||
1.31 3.018042861359369
|
||||
1.32 3.081643879863457
|
||||
1.33 3.146946354006425
|
||||
1.34 3.214009212615456
|
||||
1.35 3.282893686813416
|
||||
1.36 3.353663409560882
|
||||
1.37 3.426384519849983
|
||||
1.38 3.501125771782464
|
||||
1.39 3.577958648776878
|
||||
1.4 3.656957483162535
|
||||
1.409999999999999 3.738199581431794
|
||||
1.419999999999999 3.821765355436631
|
||||
1.429999999999999 3.907738459830743
|
||||
1.439999999999999 3.996205936074648
|
||||
1.45 4.087258363338228
|
||||
1.46 4.1809900166533
|
||||
1.47 4.277499032687774
|
||||
1.48 4.376887583533097
|
||||
1.49 4.479262058918055
|
||||
1.5 4.584733257284428
|
||||
1.51 4.693416586183766
|
||||
1.52 4.8054322724798
|
||||
1.53 4.920905582867543
|
||||
1.54 5.039967055248233
|
||||
1.55 5.162752741529169
|
||||
1.56 5.289404462448803
|
||||
1.57 5.420070075060937
|
||||
1.58 5.554903753546978
|
||||
1.59 5.694066284062637
|
||||
1.6 5.837725374364937
|
||||
1.61 5.986055979007075
|
||||
1.62 6.13924064093324
|
||||
1.63 6.297469850352028
|
||||
1.64 6.46094242181703
|
||||
1.65 6.629865890495652
|
||||
1.66 6.804456928662892
|
||||
1.669999999999999 6.984941783515976
|
||||
1.679999999999999 7.171556737468155
|
||||
1.689999999999999 7.364548592146415
|
||||
1.7 7.564175177387984
|
||||
1.71 7.770705886605176
|
||||
1.72 7.984422239966907
|
||||
1.73 8.205618476929244
|
||||
1.74 8.43460217973579
|
||||
1.75 8.671694929603422
|
||||
1.76 8.917232997408376
|
||||
1.77 9.171568070794009
|
||||
1.78 9.435068019734107
|
||||
1.79 9.708117702704745
|
||||
1.8 9.991119815744896
|
||||
1.81 10.28449578682015
|
||||
1.82 10.58868671804708
|
||||
1.83 10.90415437848731
|
||||
1.84 11.23138225038145
|
||||
1.85 11.57087663186459
|
||||
1.86 11.92316779938606
|
||||
1.87 12.28881123325021
|
||||
1.88 12.66838890989962
|
||||
1.89 13.06251066478044
|
||||
1.9 13.47181562986157
|
||||
1.91 13.89697375012563
|
||||
1.919999999999999 14.33868738361188
|
||||
1.929999999999999 14.79769298987001
|
||||
1.939999999999999 15.27476291197971
|
||||
1.95 15.77070725760681
|
||||
1.96 16.28637588490131
|
||||
1.97 16.82266049940022
|
||||
1.98 17.38049686847747
|
||||
1.99 17.96086716028695
|
||||
2. 18.56480241457556
|
||||
2.01 19.19338515320039
|
||||
2.02 19.84775213867227
|
||||
2.03 20.52909728956656
|
||||
2.04 21.23867476219554
|
||||
2.049999999999999 21.97780220852527
|
||||
2.06 22.74786422094802
|
||||
2.069999999999999 23.5503159751887
|
||||
2.08 24.38668708333797
|
||||
2.089999999999999 25.25858566976229
|
||||
2.1 26.16770268345233
|
||||
2.109999999999999 27.11581646123231
|
||||
2.12 28.10479755717558
|
||||
2.129999999999999 29.13661385454958
|
||||
2.14 30.21333597766457
|
||||
2.149999999999999 31.3371430221117
|
||||
2.16 32.51032862307257
|
||||
2.169999999999999 33.73530738264912
|
||||
2.18 35.01462167852244
|
||||
2.189999999999999 36.35094887769473
|
||||
2.2 37.74710898061626
|
||||
2.21 39.2060727226474
|
||||
2.22 40.73097016157087
|
||||
2.23 42.3250997817479
|
||||
2.24 43.99193814752662
|
||||
2.25 45.73515014065391
|
||||
2.26 47.55859981874191
|
||||
2.27 49.46636193428724
|
||||
2.28 51.46273415636842
|
||||
2.29 53.55225003994006
|
||||
2.3 55.73969279064824
|
||||
2.31 58.03010987628351
|
||||
2.319999999999999 60.42882853942212
|
||||
2.33 62.94147226946333
|
||||
2.339999999999999 65.57397829619274
|
||||
2.35 68.33261617119417
|
||||
2.359999999999999 71.22400750791783
|
||||
2.37 74.255146956017
|
||||
2.379999999999999 77.43342449070178
|
||||
2.39 80.76664910336438
|
||||
2.399999999999999 84.26307398561921
|
||||
2.41 87.93142330521251
|
||||
2.419999999999999 91.78092067900989
|
||||
2.43 95.82131945551353
|
||||
2.439999999999999 100.0629349271087
|
||||
2.45 104.516678600558
|
||||
2.46 109.1940946631549
|
||||
2.47 114.107398791505
|
||||
2.48 119.2695194601261
|
||||
2.49 124.6941419180349
|
||||
2.5 130.395755013247
|
||||
2.51 136.3897010577407
|
||||
2.52 142.6922289389604
|
||||
2.53 149.3205506984623
|
||||
2.54 156.2929018138786
|
||||
2.55 163.6286054371017
|
||||
2.56 171.3481408595211
|
||||
2.569999999999999 179.4732164944314
|
||||
2.58 188.0268476873872
|
||||
2.589999999999999 197.0334396875008
|
||||
2.6 206.5188761365411
|
||||
2.609999999999999 216.510613458281
|
||||
2.62 227.0377815581046
|
||||
2.629999999999999 238.1312912724161
|
||||
2.64 249.8239490392179
|
||||
2.649999999999999 262.1505792953359
|
||||
2.66 275.1481551425377
|
||||
2.669999999999999 288.8559378642276
|
||||
2.68 303.3156259168774
|
||||
2.689999999999999 318.5715140659986
|
||||
2.7 334.6706633855801
|
||||
2.71 351.6630828927222
|
||||
2.72 369.601923646089
|
||||
2.73 388.5436861979171
|
||||
2.74 408.5484423552258
|
||||
2.75 429.6800722766929
|
||||
2.76 452.0065180080196
|
||||
2.77 475.6000546407463
|
||||
2.78 500.537580368018
|
||||
2.79 526.9009268060783
|
||||
2.8 554.777191053032
|
||||
2.81 584.2590910670118
|
||||
2.819999999999999 615.4453460651943
|
||||
2.83 648.4410837736076
|
||||
2.839999999999999 683.358276496242
|
||||
2.85 720.3162081214007
|
||||
2.859999999999999 759.4419743442698
|
||||
2.87 800.871018558486
|
||||
2.879999999999999 844.7477060568625
|
||||
2.89 891.2259393836651
|
||||
2.899999999999999 940.469817898963
|
||||
2.91 992.6543448510879
|
||||
2.919999999999999 1047.966185507326
|
||||
2.93 1106.6044801674
|
||||
2.939999999999999 1168.781716180411
|
||||
2.95 1234.724663405969
|
||||
2.96 1304.675377905578
|
||||
2.97 1378.89227902371
|
||||
2.98 1457.651305421107
|
||||
2.99 1541.247156058746
|
||||
3. 1629.994622601567
|
60
src/tests/hypergeometricFcn/hypergeometricFcn.cpp
Normal file
60
src/tests/hypergeometricFcn/hypergeometricFcn.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <gsl_sf_hyperg.h>
|
||||
|
||||
#define PI 3.14159265359
|
||||
|
||||
extern "C" {
|
||||
double gsl_sf_hyperg_1F1(double a, double b, double x);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// load Mathematica test file
|
||||
ifstream fin;
|
||||
|
||||
fin.open("erfi.dat", iostream::in);
|
||||
if (!fin.is_open()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int max=0;
|
||||
char str[256];
|
||||
double t, fval;
|
||||
double data[3][1000];
|
||||
while (!fin.eof()) {
|
||||
fin.getline(str, sizeof(str));
|
||||
sscanf(str, "%lf %lf", &t, &fval);
|
||||
data[0][max] = t;
|
||||
data[1][max] = fval;
|
||||
max++;
|
||||
}
|
||||
|
||||
fin.close();
|
||||
|
||||
// evaluate gsl function
|
||||
for (int i=0; i<max; i++) {
|
||||
t = i*0.01;
|
||||
data[2][i] = 2*t/sqrt(PI)*gsl_sf_hyperg_1F1(1.0/2.0,3.0/2.0,t*t);
|
||||
}
|
||||
|
||||
// save everything together in an output file
|
||||
ofstream fout;
|
||||
|
||||
fout.open("erfi_gsl.dat", iostream::out);
|
||||
if (!fout.is_open()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i=0; i<max; i++) {
|
||||
fout << data[0][i] << ", " << data[1][i] << ", " << data[2][i] << endl;
|
||||
}
|
||||
|
||||
fout.close();
|
||||
|
||||
return 0;
|
||||
}
|
24
src/tests/hypergeometricFcn/hypergeometricFcn.pro
Normal file
24
src/tests/hypergeometricFcn/hypergeometricFcn.pro
Normal file
@ -0,0 +1,24 @@
|
||||
#------------------------------------------------------
|
||||
# hypergeometricFcn.pro
|
||||
# qmake file for hypergeometricFcn
|
||||
#
|
||||
# Andreas Suter, 2008/02/12
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
#------------------------------------------------------
|
||||
|
||||
MAKEFILE = Makefile
|
||||
|
||||
CONFIG += warn_on debug
|
||||
|
||||
HEADERS =
|
||||
|
||||
SOURCES = hypergeometricFcn.cpp
|
||||
|
||||
INCLUDEPATH += /usr/include/gsl
|
||||
|
||||
unix:LIBS += -lgslcblas -lgsl -lbsd -lm -ldl -lutil
|
||||
|
||||
TARGET = hypergeometricFcn
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
//#define BOOST_SPIRIT_DEBUG
|
||||
#define BOOST_SPIRIT_DEBUG
|
||||
|
||||
#include <boost/spirit/core.hpp>
|
||||
#include <boost/spirit/tree/ast.hpp>
|
||||
|
@ -18,7 +18,7 @@ PAR 1.0 2.1 3.5 -0.87 0.87
|
||||
MAP 2 1 4 5
|
||||
FUNCTIONS
|
||||
#fun0 = sin(par3/(par1+map2))
|
||||
fun1 = 1.0+(((sin(par1))))
|
||||
fun1 = 1.0+(sin(par1))
|
||||
#fun0 = par1 + map3 * cos(cos(par2 - map1))
|
||||
#fun8 = log(sin(par1)) + exp(-1.0*map2)
|
||||
#fun1 = par1 + map1 * (0.01355+par1*(2.1 - (-2.3 / 3.4)))
|
||||
|
Reference in New Issue
Block a user