I've searched to find examples of how to work with the C versions of optim. I've separated out the function just to test on it alone, and currently I'm attempting to use fmmin as follows: !~~CODE ~~! double optimfn(int n, double *par, void *ex) { double * lambda = (double*)malloc(sizeof(double)*n); double sum = 0; for(int i =0; i < n; i++) { lambda[i] = (1+tanh(par[i]/2.0))/2.0; } for(int i = 0; i < n; i++) { sum += (par[i]*log(lambda[i]) + (1-par[i]*log(1-lambda[i]))); } return sum; } void optimgr(int n, double *par, double *gr, void *ex) { for(int i = 0; i < n; i++) { gr[i] = log(par[i]) - log(1-par[i]); } } void Test(SEXP SomeValues) { PROTECT(SomeValues = AS_NUMERIC(SomeValues)); double * CValues = NUMERIC_POINTER(SomeValues); void * optEx, *grEx, *overallEx; int mask = -1, fncount, grcount, failed; double *Fmax, *gradients; int size = sizeof(CValues)/sizeof(double); vmmin(size, CValues, Fmax, optimfn, optimgr, 20, 0, mask, .00001, .000001, 40, overallEx, fncount, grcount, failed); } !~~ END CODE ~~! ---------------------------------------------- Beyond the basic optimfn/optimgr which I'll be changing... I've gotten compiler complaints about the 'implicit declaration of vmmin', which I'm a little stuck on. But even beyond that, I'm unclear as to how all of the information will be returned. The "R Extensions" does a lot of hand-waving on this subject. Could anyone provide a solid example of how this would be done properly? Also, with an output of things like the loglikelihood and gradient values, as I need to work with the returned values and not simply pass things straight back into R. I hope that was phrased clearly and not asking too much. I've looked through the manuals and other mail list questions I could find, but feel very stuck still. Thanks in advance, ~Eddie [[alternative HTML version deleted]]