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,31 @@
#include <cmath>
#include "nr.h"
using namespace std;
DP NR::rtsec(DP func(const DP), const DP x1, const DP x2, const DP xacc)
{
const int MAXIT=30;
int j;
DP fl,f,dx,xl,rts;
fl=func(x1);
f=func(x2);
if (fabs(fl) < fabs(f)) {
rts=x1;
xl=x2;
SWAP(fl,f);
} else {
xl=x1;
rts=x2;
}
for (j=0;j<MAXIT;j++) {
dx=(xl-rts)*f/(f-fl);
xl=rts;
fl=f;
rts += dx;
f=func(rts);
if (fabs(dx) < xacc || f == 0.0) return rts;
}
nrerror("Maximum number of iterations exceeded in rtsec");
return 0.0;
}