source: trunk/SRC/Interpolation/spl_fstdrv.pro @ 101

Last change on this file since 101 was 101, checked in by pinsard, 18 years ago

start to modify headers of Interpolation *.pro files for better idldoc output

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments SPL_FSTDRV returns the values of the first derivative of
7; the interpolating function at the points X2i. it is a double
8; precision array.
9;
10; Given the arrays X and Y, which tabulate a function (with the X[i]
11; AND Y[i] in ascending order), and given an input value X2, the
12; SPL_INCR function returns an interpolated value for the given values
13; of X2. The interpolation method is based on cubic spline, corrected
14; in a way that interpolated value are also in ascending order
15;
16; @examples  y2 =  spl_fstdrv(x, y, yscd, x2)
17;
18;    @param x {in}{required}  An n-element (at least 2) input vector that specifies the
19;    tabulate points in ascending order.
20;
21;    @param y {in}{required}  f(x) = y. An n-element input vector that specifies the values
22;    of the tabulated function F(Xi) corresponding to Xi.
23;
24;    @param yscd {in}{required}  The output from SPL_INIT for the specified X and Y.
25;
26;    @param x2 {in}{required}  The input values for which the first derivative values are
27;    desired. X can be scalar or an array of values.
28
29; @returns
30;
31;    y2: f'(x2) = y2.
32;
33;
34; @history
35;  Sebastien Masson (smasson\@lodyc.jussieu.fr): May 2005
36;-
37;------------------------------------------------------------
38;------------------------------------------------------------
39;------------------------------------------------------------
40FUNCTION spl_fstdrv, x, y, yscd, x2
41;
42; compute the first derivative of the spline function;
43;
44  nx = n_elements(x)
45  ny = n_elements(y)
46; x must have at least 2 elements
47  IF nx LT 2 THEN stop   
48; y must have the same number of elements than x
49  IF nx NE ny THEN stop
50; define loc in a way that
51;  if loc[i] eq -1   :                 x2[i] <  x[0]
52;  if loc[i] eq nx2-1:                 x2[i] >= x[nx-1]
53;  else              :    x[loc[i]] <= x2[i] <  x[loc[i]+1]
54  loc = value_locate(x, x2)
55; change loc in order to
56; use x[0]    and x[1]    even if x2[i] <  x[0]    -> extrapolation
57; use x[nx-2] and x[nx-1] even if x2[i] >= x[nx-1] -> extrapolation
58  loc = 0 > temporary(loc) < (nx-2)
59; distance between to consecutive x
60  deltax = x[loc+1]-x[loc]
61; distance between to consecutive y
62  deltay = y[loc+1]-y[loc]
63; relative distance between x2[i] and x[loc[i]+1]
64  a = (x[loc+1]-x2)/deltax
65; relative distance between x2[i] and x[loc[i]]
66  b = 1.0d - a
67; compute the first derivative on x (see numerical recipes Chap 3.3)
68  yfrst = temporary(deltay)/deltax $
69    - 1.0d/6.0d * (3.0d*a*a - 1.0d) * deltax * yscd[loc] $
70    + 1.0d/6.0d * (3.0d*b*b - 1.0d) * deltax * yscd[loc+1]
71; beware of the computation precision...
72; force near zero values to be exactly 0.0
73  zero = where(abs(yfrst) LT 1.e-10)
74  IF zero[0] NE -1 THEN yfrst[zero] = 0.0d
75
76  RETURN, yfrst
77END
78
Note: See TracBrowser for help on using the repository browser.