37 regels
831 B
C++
37 regels
831 B
C++
#include "JSC.h"
|
|
using namespace std;
|
|
|
|
void JSC::polint(Vect_CX& xa, Vect_CX& ya, const complex<DP> x, complex<DP>& y, complex<DP>& dy)
|
|
{
|
|
// Polynomial interpolation/extrapolation, NR page 113.
|
|
|
|
int i, m, ns=0;
|
|
DP dif, dift;
|
|
complex<DP> den, ho, hp, w;
|
|
|
|
int n = xa.size();
|
|
Vect_CX c(n), d(n);
|
|
dif = abs(x-xa[0]);
|
|
for (i = 0; i < n; i++) {
|
|
if ((dift = abs(x-xa[i])) < dif) {
|
|
ns = i;
|
|
dif = dift;
|
|
}
|
|
c[i] = ya[i];
|
|
d[i] = ya[i];
|
|
}
|
|
y = ya[ns--];
|
|
for (m = 1; m < n; m++) {
|
|
for (i = 0; i < n-m; i++) {
|
|
ho = xa[i] - x;
|
|
hp = xa[i+m] - x;
|
|
w = c[i+1] - d[i];
|
|
if ((den = ho-hp) == 0.0) JSCerror("Error in routine polint_cx.");
|
|
den = w/den;
|
|
d[i] = hp * den;
|
|
c[i] = ho * den;
|
|
}
|
|
y += (dy = (2 * (ns + 1) < (n-m) ? c[ns + 1] : d[ns--]));
|
|
}
|
|
}
|