add numerical recipes library
This commit is contained in:
39
lib/nr/ansi/recipes/linmin.c
Normal file
39
lib/nr/ansi/recipes/linmin.c
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
#define NRANSI
|
||||
#include "nrutil.h"
|
||||
#define TOL 2.0e-4
|
||||
|
||||
int ncom;
|
||||
float *pcom,*xicom,(*nrfunc)(float []);
|
||||
|
||||
void linmin(float p[], float xi[], int n, float *fret, float (*func)(float []))
|
||||
{
|
||||
float brent(float ax, float bx, float cx,
|
||||
float (*f)(float), float tol, float *xmin);
|
||||
float f1dim(float x);
|
||||
void mnbrak(float *ax, float *bx, float *cx, float *fa, float *fb,
|
||||
float *fc, float (*func)(float));
|
||||
int j;
|
||||
float xx,xmin,fx,fb,fa,bx,ax;
|
||||
|
||||
ncom=n;
|
||||
pcom=vector(1,n);
|
||||
xicom=vector(1,n);
|
||||
nrfunc=func;
|
||||
for (j=1;j<=n;j++) {
|
||||
pcom[j]=p[j];
|
||||
xicom[j]=xi[j];
|
||||
}
|
||||
ax=0.0;
|
||||
xx=1.0;
|
||||
mnbrak(&ax,&xx,&bx,&fa,&fx,&fb,f1dim);
|
||||
*fret=brent(ax,xx,bx,f1dim,TOL,&xmin);
|
||||
for (j=1;j<=n;j++) {
|
||||
xi[j] *= xmin;
|
||||
p[j] += xi[j];
|
||||
}
|
||||
free_vector(xicom,1,n);
|
||||
free_vector(pcom,1,n);
|
||||
}
|
||||
#undef TOL
|
||||
#undef NRANSI
|
||||
Reference in New Issue
Block a user