aimsdata  5.1.2
Neuroimaging data handling
lagrange.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 /*
35  * Lagrange's interpolation.
36  */
37 #ifndef AIMS_MATH_LAGRANGE_H
38 #define AIMS_MATH_LAGRANGE_H
39 
40 #include <cstdlib>
43 #include <vector>
44 #include <math.h>
45 
46 namespace aims
47 {
48 
55 template <class REAL>
56 AIMSDATA_API REAL AimsLagrangeInterpolation( const std::vector<REAL> &xa,
57  const std::vector<REAL> &ya,
58  REAL x, REAL *dy )
59 
60 
61 {
62  int i,m,ns=0,n=std::min( xa.size(), ya.size() );
63  REAL den,dif,dift,ho,hp,w;
64  REAL *c, *d, y;
65 
66  dif = fabs(x-xa[0]);
67  c = new float[n];
68  d = new float[n];
69 
70  for (i=0;i<n;i++) {
71  if ((dift = fabs(x-xa[i])) < dif)
72  {
73  ns = i;
74  dif = dift;
75  }
76  c[i] = ya[i];
77  d[i] = ya[i];
78  }
79 
80  y = ya[ns--];
81  for (m=1;m<n;m++){
82  for (i=0;i<n-m;i++){
83  ho = xa[i] - x;
84  hp = xa[i+m] - x;
85  w = c[i+1] - d[i];
86  ASSERT( (den = ho - hp) != 0.0 );
87  den = w / den;
88  d[i] = hp * den;
89  c[i] = ho * den;
90  }
91  y += (*dy=(2*ns+2 < (n-m) ? c[ns+1] : d[ns--]));
92  }
93  delete [] c;
94  delete [] d;
95  return y;
96 }
97 
98 } // namespace aims
99 
100 #endif
#define AIMSDATA_API
#define ASSERT(EX)
The class for EcatSino data write operation.
Definition: borderfiller.h:13
AIMSDATA_API REAL AimsLagrangeInterpolation(const std::vector< REAL > &xa, const std::vector< REAL > &ya, REAL x, REAL *dy)
Returns the interpolation of a function defined at (xa,ya) points at x (dy is the error)
Definition: lagrange.h:56