Revision 795 branches/replacement/src/linad99/vspline.cpp
vspline.cpp (revision 795)  

4  4 
* Author: David Fournier 
5  5 
* Copyright (c) 2009 ADMB Foundation 
6  6 
*/ 
7 
/** 

8 
* \file 

9 
* Contains routines for cubic spline interpolation 

10 
* for variable types. 

11 
*/ 

12  
7  13 
#include <fvar.hpp> 
8  14  
9  15 
dvar_vector spline(const dvector &x,const dvar_vector&y,double yp1,double ypn); 
...  ...  
17  23 
dvar_vector spline_cubic_set (int n,_CONST dvector& t,_CONST dvar_vector& y, 
18  24 
int ibcbeg, dvariable ybcbeg, int ibcend, dvariable ybcend ); 
19  25  
20  
21  26 
/** \ingroup cub_spline 
22  27 
* Cubic spline interpolation. 
23  28 
* 
...  ...  
27  32 
* \param x the input coordinate to be used in the interpolation 
28  33 
* \return a cubicspline interpolation to \f$f(x)\f$ 
29  34 
*/ 
30 
dvariable splint(const dvector& _xa,const dvar_vector& _ya,


35 
dvariable splint(const dvector& _xa,const dvar_vector& _ya, 

31  36 
const dvar_vector& _y2a,double x) 
32 
{


33 
RETURN_ARRAYS_INCREMENT();


34 
dvariable ret = spline_cubic_val(_xa.size(), _xa, x, _ya, _y2a);


35 
RETURN_ARRAYS_DECREMENT();


36 
return ret;


37 
}


37 
{ 

38 
RETURN_ARRAYS_INCREMENT(); 

39 
dvariable ret = spline_cubic_val(_xa.size(), _xa, x, _ya, _y2a); 

40 
RETURN_ARRAYS_DECREMENT(); 

41 
return ret; 

42 
} 

38  43  
39  44 
/** \ingroup cub_spline 
40  45 
* Cubic spline interpolation. 
...  ...  
45  50 
* \param x the input coordinate to be used in the interpolation 
46  51 
* \return a cubicspline interpolation to \f$f(x)\f$ 
47  52 
*/ 
48 
dvariable splint(const dvector& _xa,const dvar_vector& _ya,


53 
dvariable splint(const dvector& _xa,const dvar_vector& _ya, 

49  54 
const dvar_vector& _y2a, const prevariable& _x) 
50 
{


51 
RETURN_ARRAYS_INCREMENT();


52 
dvariable ret = spline_cubic_val2(_xa.size(), _xa, _x, _ya, _y2a);


53 
RETURN_ARRAYS_DECREMENT();


54 
return ret;


55 
}


55 
{ 

56 
RETURN_ARRAYS_INCREMENT(); 

57 
dvariable ret = spline_cubic_val2(_xa.size(), _xa, _x, _ya, _y2a); 

58 
RETURN_ARRAYS_DECREMENT(); 

59 
return ret; 

60 
} 

56  61  
57  
58  
59  62 
vcubic_spline_function::vcubic_spline_function(const dvector & _x, 
60  63 
const dvar_vector& _y,dvariable yp1,dvariable ypn) : x(_x) , y(_y) 
61  64 
{ 
...  ...  
100  103 
return z; 
101  104 
} 
102  105  
103  
104  106 
/** \ingroup cub_spline 
105  107 
* Cubic spline interpolation. 
106  108 
* 
...  ...  
112  114 
* end point 
113  115 
* \return an array containing the second derivatives 
114  116 
*/ 
115 
dvar_vector spline(const dvector &_x,const dvar_vector&_y,dvariable yp1,


117 
dvar_vector spline(const dvector &_x,const dvar_vector&_y,dvariable yp1, 

116  118 
dvariable ypn) 
117 
{ 

118 
int ibcbeg, ibcend; 

119 
dvariable ybcbeg, ybcend; 

120 
dvector x = _x; 

121 
x.shift(0); 

122 
dvar_vector y = _y; 

123 
y.shift(0); 

124 
if(value(yp1) > 0.99e30 ) 

125 
{ 

126 
ibcbeg = 2; 

127 
ybcbeg = 0.0; 

128 
} 

129 
else 

130 
{ 
Also available in: Unified diff