25 static double *vector(
int n) {
28 b = (
double *) malloc(
sizeof(
double) *
n);
35 #define FUNC(x) ((*func)(x))
45 static double trapzd(
double(*func)(
double),
double a,
double b,
int n) {
46 double x, tnm,
sum, del;
51 return (s = 0.5 * (b - a) * (
FUNC(a) +
FUNC(b)));
53 for(it = 1, j = 1; j < n - 1; j++) it <<= 1;
57 for(sum = 0.0, j = 1; j <= it; j++, x += del) sum +=
FUNC(x);
58 s = 0.5 * (s + (b - a) * sum / tnm);
73 double xa[],
double ya[],
int n,
74 double x,
double *y,
double *dy) {
76 double den, dif, dift, ho, hp, w;
79 dif =
fabs(x - xa[1]);
82 for(i = 1; i <=
n; i++) {
83 if((dift =
fabs(x - xa[i])) < dif) {
91 for(m = 1; m <
n; m++) {
92 for(i = 1; i <= n - m; i++) {
96 if((den = ho - hp) == 0.0) {
99 fprintf(stderr,
"Polint: n=%d, i=%d\n", n, i);
100 for(j = 0; j <
n; j++) fprintf(stderr,
"%5d %20.12e %20.12e\n", j, xa[j], ya[j]);
107 *y += (*dy = (2 * ns < (n - m) ? c[ns+1] : d[ns--]));
117 #define JMAXP (JMAX+1)
127 double(*func)(
double),
130 double aeps, ss, dss;
136 for(j = 1; j <=
JMAX; j++) {
137 s[j] = trapzd(func, a, b, j);
139 polint(&h[j-
K], &s[j-
K],
K, 0.0, &ss, &dss);
140 if(
fabs(dss) < aeps *
fabs(ss))
return ss;
143 h[j+1] = 0.25 * h[j];
double qromb(double(*func)(double), double a, double b, double eps)
void writeBetError(std::string err)
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
constexpr double c
The velocity of light in m/s.