home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / JPLC2.ZIP / RKSTEP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-22  |  1.3 KB  |  37 lines

  1. /* 1.0  01-22-85 */
  2. /************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1985        *
  6.  ************************************************************************
  7.  *    Integration step of first-order ordinary differential equation
  8.  *    using the 4th-order Runge-Kutta formulas, given in
  9.  *
  10.  *    HANDBOOK OF MATHEMATICAL FUNCTIONS, U. S. Dept. of Commerce,
  11.  *    National Bureau of Standards Applied Mathematics Series No. 55,
  12.  *    formula 25.5.10, page 896, June, 1964.
  13.  *
  14.  *----------------------------------------------------------------------*/
  15.  
  16. #include "defs.h"
  17. #include "stdtyp.h"
  18.  
  19. /************************************************************************/
  20.     VOID
  21. rkstep(f, h, t, yp)    /* Store approximate y(t+h), for y' = f(t, y),
  22.                where y = *yp, using 4th-order Runge-Kutta
  23.                method.                    */
  24. /*----------------------------------------------------------------------*/
  25. double (*f)(), h, t, *yp;
  26. {
  27.     double k1, k2, k3, k4, h2, y, ldexp();
  28.  
  29.     h2 = ldexp(h, -1);
  30.     y = *yp;
  31.     k1 = h * (*f)(t, y);
  32.     k2 = h * (*f)(t + h2, y + ldexp(k1, -1));
  33.     k3 = h * (*f)(t + h2, y + ldexp(k2, -1));
  34.     k4 = h * (*f)(t + h, y + k3);
  35.     *yp += (k1 + ldexp(k2 + k3, 1) + k4) / 6.0;
  36. }
  37.