add numerical recipes library

This commit is contained in:
2025-09-12 18:55:25 +09:00
parent d4dff245bd
commit 2c75620ec9
1344 changed files with 63869 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
#include <math.h>
#define MAXIT 30
float rtflsp(float (*func)(float), float x1, float x2, float xacc)
{
void nrerror(char error_text[]);
int j;
float fl,fh,xl,xh,swap,dx,del,f,rtf;
fl=(*func)(x1);
fh=(*func)(x2);
if (fl*fh > 0.0) nrerror("Root must be bracketed in rtflsp");
if (fl < 0.0) {
xl=x1;
xh=x2;
} else {
xl=x2;
xh=x1;
swap=fl;
fl=fh;
fh=swap;
}
dx=xh-xl;
for (j=1;j<=MAXIT;j++) {
rtf=xl+dx*fl/(fl-fh);
f=(*func)(rtf);
if (f < 0.0) {
del=xl-rtf;
xl=rtf;
fl=f;
} else {
del=xh-rtf;
xh=rtf;
fh=f;
}
dx=xh-xl;
if (fabs(del) < xacc || f == 0.0) return rtf;
}
nrerror("Maximum number of iterations exceeded in rtflsp");
return 0.0;
}
#undef MAXIT