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,38 @@
#include <cmath>
#include "nr.h"
using namespace std;
namespace {
DP func(DP funk(const DP), const DP bb, const DP x)
{
return 2.0*x*funk(bb-x*x);
}
}
DP NR::midsqu(DP funk(const DP), const DP aa, const DP bb, const int n)
{
DP x,tnm,sum,del,ddel,a,b;
static DP s;
int it,j;
b=sqrt(bb-aa);
a=0.0;
if (n == 1) {
return (s=(b-a)*func(funk,bb,0.5*(a+b)));
} else {
for(it=1,j=1;j<n-1;j++) it *= 3;
tnm=it;
del=(b-a)/(3.0*tnm);
ddel=del+del;
x=a+0.5*del;
sum=0.0;
for (j=0;j<it;j++) {
sum += func(funk,bb,x);
x += ddel;
sum += func(funk,bb,x);
x += del;
}
s=(s+(b-a)*sum/tnm)/3.0;
return s;
}
}