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

Last change on this file since 360 was 325, checked in by pinsard, 17 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

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