1 /* interpolation/interp_poly.c
3 * Copyright (C) 2001 DAN, HO-JIN
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /* Modified for standalone use in polynomial directory, B.Gough 2001 */
23 #include <gsl/gsl_errno.h>
24 #include <gsl/gsl_poly.h>
27 gsl_poly_dd_init (double dd[], const double xa[], const double ya[],
32 /* Newton's divided differences */
36 for (j = size - 1; j >= 1; j--)
38 dd[j] = (ya[j] - ya[j - 1]) / (xa[j] - xa[j - 1]);
41 for (i = 2; i < size; i++)
43 for (j = size - 1; j >= i; j--)
45 dd[j] = (dd[j] - dd[j - 1]) / (xa[j] - xa[j - i]);
52 #ifndef HIDE_INLINE_STATIC
54 gsl_poly_dd_eval (const double dd[], const double xa[], const size_t size, const double x)
57 double y = dd[size - 1];
59 for (i = size - 1; i--;)
61 y = dd[i] + (x - xa[i]) * y;
69 gsl_poly_dd_taylor (double c[], double xp,
70 const double dd[], const double xa[], size_t size,
75 for (i = 0; i < size; i++)
85 for (i = size - 1; i > 0 && i--;)
87 w[i] = -w[i + 1] * (xa[size - 2 - i] - xp);
89 for (j = i + 1; j < size - 1; j++)
91 w[j] = w[j] - w[j + 1] * (xa[size - 2 - i] - xp);
94 for (j = i; j < size; j++)
96 c[j - i] += w[j] * dd[size - i - 1];