DERIV Function
Standard Library function that calculates the first derivative of a function in x and y.
Usage
Input Parameters
x — (optional) The vector of independent x-coordinates of the data (i.e., the variable with respect to which the function should be differentiated). Must be a one-dimensional array (a vector).
y — The vector of dependent y-coordinates at which the derivative of function f is evaluated. Must be a one-dimensional array (a vector).
Returned Value
result — The first derivative of the vector y, with respect to the independent variable x. The result has the same size as y.
Keywords
None.
Discussion
Note: DERIV does not support complex numbers. |
The numerical differentiation algorithm for DERIV uses a three-point Lagrangian interpolation.
The vector of x-coordinates, x, is optional. The conditions set on this vector are given below:
-
If you specify x, then both x and y must be one-dimensional and have the same number of elements. Selecting this option allows you to define the spacing along the x-axis, for the case where the independent data is not monotonically increasing.
-
If you don’t specify x, then it is automatically provided with even spacing, using a unit of one, along the x-axis. (In other words,
x(i) = i, where i = 0, 1, 2, 3, ... n.)
Example 1
x = FINDGEN(10) xx = x^2 d = DERIV(xx) PRINT, d ; PV-WAVE prints: ; 1.00000 2.00000 4.00000 ; 6.00000 8.00000 ; 10.0000 12.0000 14.0000 ; 16.0000 17.0000 PLOT, xx OPLOT, d, Linestyle=2
Example 2
Create array with values 0, 10, 20 ... and multiply these by !Dtor (which equals 0.0174533) to convert the values from degrees to radians.
x = FINDGEN(100) * 10 * !Dtor sin_x = SIN(x) d_sin_x = DERIV(x, sin_x) PLOT, sin_x OPLOT, d_sin_x, Linestyle=2
See Also
For an example of the three-point Lagrangian interpolation used in DERIV, see the Introduction to Numerical Analysis by F. B. Hildebrand, Dover Publishing, New York, 1987.