add numerical recipes library
This commit is contained in:
35
lib/nr/k_and_r/recipes/rofunc.c
Normal file
35
lib/nr/k_and_r/recipes/rofunc.c
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
#include <math.h>
|
||||
#include "nrutil.h"
|
||||
#define EPS 1.0e-7
|
||||
|
||||
extern int ndatat;
|
||||
extern float *xt,*yt,aa,abdevt;
|
||||
|
||||
float rofunc(b)
|
||||
float b;
|
||||
{
|
||||
float select();
|
||||
int j;
|
||||
float *arr,d,sum=0.0;
|
||||
|
||||
arr=vector(1,ndatat);
|
||||
for (j=1;j<=ndatat;j++) arr[j]=yt[j]-b*xt[j];
|
||||
if (ndatat & 1) {
|
||||
aa=select((ndatat+1)>>1,ndatat,arr);
|
||||
}
|
||||
else {
|
||||
j=ndatat >> 1;
|
||||
aa=0.5*(select(j,ndatat,arr)+select(j+1,ndatat,arr));
|
||||
}
|
||||
abdevt=0.0;
|
||||
for (j=1;j<=ndatat;j++) {
|
||||
d=yt[j]-(b*xt[j]+aa);
|
||||
abdevt += fabs(d);
|
||||
if (yt[j] != 0.0) d /= fabs(yt[j]);
|
||||
if (fabs(d) > EPS) sum += (d >= 0.0 ? xt[j] : -xt[j]);
|
||||
}
|
||||
free_vector(arr,1,ndatat);
|
||||
return sum;
|
||||
}
|
||||
#undef EPS
|
||||
Reference in New Issue
Block a user