1 /*$Id: m_divdiff.h,v 26.81 2008/05/27 05:34:00 al Exp $ -*- C++ -*-
2  * Copyright (C) 2001 Albert Davis
3  * Author: Albert Davis <aldavis@gnu.org>
4  *
5  * This file is part of "Gnucap", the Gnu Circuit Analysis Package
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  *------------------------------------------------------------------
22  * divided differences
23  * in:
24  *   c = numerator (data points) (lost)
25  *   t = denominator (time)
26  *   n = size of array
27  *   # of divided differences == n-1
28  * out:
29  *   c = "divided differences" (mult by n! to get derivative)
30  */
31 //testing=script,complete 2006.07.13
32 /*--------------------------------------------------------------------------*/
33 #if 0
34 template<class T1, class T2>
35 inline void divided_differences(T1 c[], int n, const T2 t[])
36 {
37   untested();
38   for (int d=1; d<n; ++d) {
39     untested();
40     for (int i=n-1; i>=d; --i) {
41       untested();
42       c[i] = (c[i-1] - c[i]) / (t[i-d] - t[i]);
43     }
44   }
45 }
46 #endif
47 /*--------------------------------------------------------------------------*/
48 template<class T1, class T2>
derivatives(T1 c[],int n,const T2 t[])49 inline void derivatives(T1 c[], int n, const T2 t[])
50 {
51   for (int d=1; d<n; ++d) {
52     for (int i=n-1; i>=d; --i) {
53       c[i] = d * (c[i-1] - c[i]) / (t[i-d] - t[i]);
54     }
55   }
56 }
57 /*--------------------------------------------------------------------------*/
58 /*--------------------------------------------------------------------------*/
59