Index Page uddf_c
A B C D E F G H I J K L M N O P Q R S T U V W X
Procedure Abstract Required_Reading Keywords Brief_I/O Detailed_Input | Detailed_Output Parameters Exceptions Files Particulars Examples | Restrictions Literature_References Author_and_Institution Version Index_Entries
#### Procedure
       void uddf_c (  void             ( * udfunc ) ( SpiceDouble    et,
                                                      SpiceDouble  * value ),
                      SpiceDouble          x,
                      SpiceDouble          dx,
                      SpiceDouble        * deriv )
#### Abstract
       Routine to calculate the first derivative of a caller-specified
       function using a three-point estimation.
#### Required_Reading
       None.
#### Keywords
       DERIVATIVE
#### Brief_I/O
         Variable  I/O  Description
         --------  ---  --------------------------------------------------
         udfunc     I   Name of the routine that computes the scalar value
                        of interest.
         x          I   Independent variable of 'udfunc'
         dx         I   Interval from 'x' for derivative calculation
         deriv      O   Approximate derivative of 'udfunc' at 'x'
#### Detailed_Input
         udfunc     is an externally specified routine that returns the
                    value of the scalar quantity function of interest
                    at x.

                    The prototype for 'udfunc' is

                        void   ( * udfunc ) ( SpiceDouble    et,
                                              SpiceDouble  * value )

                    where:

                        et      an input double precision value of the independent
                                variable the function at which to determine the
                                scalar value.

                        value   the scalar double precision value of 'udfunc'
                                at 'x'.

         x          a scalar double precision value representing the independent
                    variable at which to determine the derivative of 'udfunc'.

                    For many SPICE uses, 'x' will represent the TDB ephemeris
                    time.

         dx         a scalar double precision value representing half the
                    interval in units of X separating the evaluation
                    epochs of UDFUNC; the evaluations occur at (x + dx))
                    and (x - dx).

                    'dx' may be negative but must be non-zero.
#### Detailed_Output
         deriv      the scalar double precision approximate value of the
                    first derivative of udfunc with respect to 'x'.

                    Functionally:

                                d  udfunc ( x )
                       deriv =  --
                                dx
#### Parameters
       None.
#### Exceptions
       None.
#### Files
       None.
#### Particulars
       This routine provides a simple interface to numerically calculate
       the first derivative of a scalar quantity function.
#### Examples
       The numerical results shown for these examples may differ across
       platforms. The results depend on the SPICE kernels used as
       input, the compiler and supporting libraries, and the machine
       specific arithmetic implementation.

          #include <stdio.h>
          #include "SpiceUsr.h"

          void udfunc ( SpiceDouble et, SpiceDouble * value );

          int main()
             {

             SpiceDouble       et;
             SpiceDouble       dt;
             SpiceDouble       deriv;

             /.
             Load leapsecond and SPK kernels. The name of the
             meta kernel file shown here is fictitious; you
             must supply the name of a file available
             on your own computer system.
             ./

             furnsh_c ( "standard.tm" );

             /.
             Use a shift of one second off the epoch of interest.
             ./
             dt = 1.;

             /.
             Convert the epoch date string to ephemeris seconds.
             ./
             str2et_c ( "JAN 1 2009", &et );

             /.
             Calculate the derivative of UDFUNC at ET.
             ./
             uddf_c( udfunc, et, dt, &deriv );

             /.
             Output the calculated derivative.
             ./

             printf( "%18.12f\n", deriv );

             return ( 0 );
             }

          /.
          A scalar quantity function that returns the light-time
          between the Moon and Mercury at 'et'.
          ./

          void udfunc ( SpiceDouble et, SpiceDouble * value )
             {

             SpiceDouble          lt;
             SpiceDouble          pos[3];

             /.
             Evaluate the apparent position of Mercury with respect
             to the Moon at 'et'.
             ./
             spkpos_c ( "MERCURY", et, "J2000", "LT+S", "MOON", pos, &lt );

             /.
             Return the light-time value as the scalar quantity.
             ./
             *value = lt;

             return;
             }

       The program outputs:

          -0.000135670940
#### Restrictions
       'udfunc' must evaluate to real values at x + dx and x - dx.
#### Literature_References
       See qderiv.c header.
#### Author_and_Institution
       N.J. Bachman   (JPL)
       E.D. Wright    (JPL)
#### Version
       CSPICE Version 1.0.0  31-MAR-2010 (EDW)
#### Index_Entries
       first derivative of a function
#### Link to routine uddf_c source file uddf_c.c

    Wed Jun  9 13:05:31 2010