GNU Scientific Library (GSL) 是用于数值计算的 C 和 C++ 程序库,提供了广泛的的数学例程如随机数产生器,特殊函数和最小二乘拟和。
安装:
apt-get install update
apt-get install gsl
如果说是手动安装要指定库在什么地方:
//
./configure --prefix=/home/yourname/dev
//
测试程序testGsl.c:
#include <stdio.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
int main (int argc, char *argv[])
{
/* set up GSL RNG */
gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937);
/* end of GSL setup */
unsigned long tmpseed = getpid();
gsl_rng_set(r,tmpseed);
int i,n;
double gamma;
for (i=0;i<5;i++)
{
gamma=gsl_ran_gamma(r,2.0,3.0);
printf("%f\n",gamma);
}
return(0);
}
~
~
编译运行:
//
gcc -Wall -I/home/hanss/dev/include -c example.c
gcc -L/home/hanss/dev/lib example.o -lgsl -lgslcblas -lm
./a.out
//