void uddf_c ( void ( * udfunc ) ( SpiceDouble et,
SpiceDouble * value ),
SpiceDouble x,
SpiceDouble dx,
SpiceDouble * deriv )
Routine to calculate the first derivative of a caller-specified
function using a three-point estimation.
None.
DERIVATIVE
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'
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.
deriv the scalar double precision approximate value of the
first derivative of udfunc with respect to 'x'.
Functionally:
d udfunc ( x )
deriv = --
dx
None.
None.
None.
This routine provides a simple interface to numerically calculate
the first derivative of a scalar quantity function.
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, < );
/.
Return the light-time value as the scalar quantity.
./
*value = lt;
return;
}
The program outputs:
-0.000135670940
'udfunc' must evaluate to real values at x + dx and x - dx.
See qderiv.c header.
N.J. Bachman (JPL)
E.D. Wright (JPL)
CSPICE Version 1.0.0 31-MAR-2010 (EDW)
first derivative of a function
Link to routine uddf_c source file uddf_c.c
|