45 x = f0 = f1 = f2 = f3 = NULL;
53 x = f0 = f1 = f2 = f3 = NULL;
61 x = f0 = f1 = f2 = f3 = NULL;
71 x = f0 = f1 = f2 = f3 = NULL;
85 assert (y.
getSize () == i && i >= 3);
89 for (i = 0; i <= n; i++) {
97 assert (y.
getSize () == i && i >= 3);
101 for (i = 0; i <= n; i++) {
102 f0[
i] =
y_(i); x[
i] =
t_(i);
113 for (i = 0; i <= n; i++) {
114 f0[
i] = y[
i]; x[
i] = t[
i];
119 void spline::realloc (
int size) {
123 f0 =
new nr_double_t[n+1];
125 x =
new nr_double_t[n+1];
127 if (f1) {
delete[] f1; f1 = NULL; }
128 if (f2) {
delete[] f2; f2 = NULL; }
129 if (f3) {
delete[] f3; f3 = NULL; }
137 nr_double_t * h =
new nr_double_t[n+1];
138 for (i = 0; i < n; i++) {
139 h[
i] = x[i+1] - x[
i];
150 nr_double_t *
b =
new nr_double_t[n+1];
151 for (i = 1; i < n; i++) {
152 nr_double_t _n = f0[i+1] * h[i-1] - f0[
i] * (h[
i] + h[i-1]) +
154 nr_double_t _d = h[i-1] * h[
i];
163 b[0] = 3 * ((f0[1] - f0[0]) / h[0] - d0);
164 b[n] = 3 * (dn - (f0[n] - f0[n-1]) / h[n-1]);
167 nr_double_t * u =
new nr_double_t[n+1];
173 u[0] = h[0] / (2 * h[0]);
174 z[0] = b[0] / (2 * h[0]);
177 for (i = 1; i < n; i++) {
178 nr_double_t p = 2 * (h[
i] + h[i-1]) - h[i-1] * u[i-1];
180 z[
i] = (b[
i] - z[i-1] * h[i-1]) / p;
185 nr_double_t p = h[n-1] * (2 - u[n-1]);
186 z[n] = (b[n] - z[n-1] * h[n-1]) / p;
195 for (i = n - 1; i >= 0; i--) {
196 f2[
i] = z[
i] - u[
i] * f2[i+1];
197 f1[
i] = (f0[i+1] - f0[
i]) / h[i] - h[i] * (f2[i+1] + 2 * f2[i]) / 3;
198 f3[
i] = (f2[i+1] - f2[
i]) / (3 * h[i]);
203 f1[n] = f1[n-1] + (x[n] - x[n-1]) * f2[n-1];
214 nr_double_t * z =
new nr_double_t[n+1];
216 nr_double_t
B = h[0] + h[1];
217 nr_double_t
A = 2 *
B;
218 nr_double_t
b[2],
det;
219 b[0] = 3 * ((f0[2] - f0[1]) / h[1] - (f0[1] - f0[0]) / h[0]);
220 b[1] = 3 * ((f0[1] - f0[2]) / h[0] - (f0[2] - f0[1]) / h[1]);
222 z[1] = ( A * b[0] - B * b[1]) / det;
223 z[2] = (-B * b[0] + A * b[1]) / det;
232 for (i = 0; i < n - 1; i++) {
234 d(i) = 2 * (h[i+1] + h[
i]);
235 b(i) = 3 * ((f0[i+2] - f0[i+1]) / h[i+1] - (f0[i+1] - f0[i]) / h[
i]);
238 d(i) = 2 * (h[0] + h[
i]);
239 b(i) = 3 * ((f0[1] - f0[i+1]) / h[0] - (f0[i+1] - f0[i]) / h[
i]);
248 f1 =
new nr_double_t[n+1];
251 for (i = n - 1; i >= 0; i--) {
252 f1[
i] = (f0[i+1] - f0[
i]) / h[i] - h[i] * (z[i+1] + 2 * z[i]) / 3;
253 f3[
i] = (z[i+1] - z[
i]) / (3 * h[i]);
262 nr_double_t * spline::upper_bound (nr_double_t * first, nr_double_t * last,
264 int half, len = last - first;
265 nr_double_t * centre;
276 len = len - half - 1;
285 #ifndef PERIOD_DISABLED
288 nr_double_t period = x[n] - x[0];
289 while (t > x[n]) t -= period;
290 while (t < x[0]) t += period;
294 nr_double_t * here = upper_bound (x, x+n+1, t);
295 nr_double_t y0, y1, y2;
297 nr_double_t dx = t - x[0];
298 y0 = f0[0] + dx * f1[0];
300 return poly (t, y0, y1);
303 int i = here - x - 1;
304 nr_double_t dx = t - x[
i];
306 y0 = f0[
i] + dx * (f1[
i] + dx * (f2[
i] + dx * f3[
i]));
308 y1 = f1[
i] + dx * (2 * f2[
i] + 3 * dx * f3[
i]);
310 y2 = 2 * f2[
i] + 6 * dx * f3[
i];
311 return poly (t, y0, y1, y2);