## In expo.c #include #include double expo(double a, double b, double x){ // Computes a exp(bx) return(a * exp(b*x)); } void mysimp(double *start,double *stop,long *n, double *a, double *b, double *ans){ /* integrates aexp(bx) from start to stop numerically, using n rectangles. */ double mult,x,t,inc; long i; inc = (*stop - *start) / (double) *n; x = *start; t = expo(*a, *b, x); for(i=1; i< *n; i++){ x += inc; t += expo(*a, *b, x); } *ans = t * inc; } system("R CMD SHLIB expo2.c") dyn.load("expo2.so") a = 2.5 b = 3.5 c = 1.0 d = 4.0 n = 100000000 y = .C("mysimp",as.double(c), as.double(d), as.integer(n), as.double(a), as.double(b),as.double(0.0)) ## compare with the integral of a exp(bx) from x = c to d ## = a/b * (exp(b*d) - exp(b*c)) ## = 858979.4. y[[6]]