R 教材:Standalone |
SHELL> tar zxvf R-1.7.1.tgz SHELL> cd R-1.7.1/ SHELL> ./configure; make SHELL> cd src/nmath/standalone/ SHELL> make shared SHELL> cp libRmath.so /usr/lib/R/bin/ SHELL> cd /usr/lib SHELL> ln -s /usr/lib/libRmath.so ./R/bin/libRmath.so |
#define MATHLIB_STANDALONE #include <Rmath.h> int main(){ int i; unsigned int SEED1, SEED2; double mu, sigma, PHI_X, *X; mu = 0; sigma = 1; SEED1 = 12345; SEED2 = 67890; set_seed(SEED1, SEED2); X = (double *) malloc(10); for(i = 0; i < 10; i++){ X[i] = rnorm(mu, sigma); PHI_X = pnorm(X[i], mu, sigma, 1, 0); printf("X: %f, PHI(X): %f\n", X[i], PHI_X); } } |
SHELL> gcc -o stand stand.c -I/usr/lib/R/include/ -lRmath -lm |
X: 0.999948, PHI(X): 0.841332 X: -1.768380, PHI(X): 0.038499 X: 0.623938, PHI(X): 0.733666 X: 2.167754, PHI(X): 0.984911 X: 0.749400, PHI(X): 0.773192 X: -1.253019, PHI(X): 0.105099 X: 0.640719, PHI(X): 0.739147 X: 0.567502, PHI(X): 0.714814 X: -1.744883, PHI(X): 0.040503 X: 0.140647, PHI(X): 0.555925 |
陳韋辰 (04/08/19) --- |