  ode
  Builtin Function



      SSyynnooppssiiss
        Integrate Ordinary Differential Equations.

      SSyynnttaaxx
        ode ( _r_h_s_f, _t_s_t_a_r_t, _t_e_n_d, _y_s_t_a_r_t, _d_t_o_u_t, _r_e_l_e_r_r, _a_b_s_e_r_r, _u_o_u_t )

      DDeessccrriippttiioonn
        ode integrates a system of N first order ordinary differential
        equations of the form:



          dy(i)/dt = f(t,y(1),y(2),...,y(N))
          y(i) given at  t .





     The arguments to ode are:


        _r_h_s_f
           A function that evaluates dy(i)/dt at t. The function takes
           two arguments and returns dy/dt. An example that generates
           dy/dt for Van der Pol's equation is shown below.



             vdpol = function ( t , x )
             {
               xp = zeros(2,1);
               xp[1] = x[1] * (1 - x[2]^2) - x[2];
               xp[2] = x[1];
               return xp;
             };






        _y_s_t_a_r_t
           The initial values of y, y(tstart).


        _t_s_t_a_r_t
           The initial value of the independent variable.


        _t_e_n_d
           The final value of the independent variable.


        _d_t_o_u_t
           The output interval. The vector y will be saved at _t_s_t_a_r_t,
           increments of _t_s_t_a_r_t + _d_t_o_u_t, and _t_e_n_d. If _d_t_o_u_t is not
           specified, then the default is to store output at 101 values
           of the independent variable.


        _r_e_l_e_r_r
           The relative error tolerance. Default value is 1.e-6.


        _a_b_s_e_r_r
           The absolute error tolerance. At each step, ode requires
           that:


             abs(local error) <= abs(y)*relerr + abserr


        For each component of the local error and solution vectors. The
        default value is 1.e-6.


        _u_o_u_t
           Optional. A user-supplied function that computes an arbitrary
           output during the integration. _u_o_u_t must return a row-matrix
           at each dtout during the integration. It is entirely up to
           the user what to put in the matrix. The matrix is used to
           build up a larger matrix of the output, with one row for each
           _d_t_o_u_t. The resulting matrix is returned by ode when the
           integration is complete.


     The Fortran source code for ode is completely explained and
     documented in the text, "Computer Solution of Ordinary Differential
     Equations: The Initial Value Problem" by L. F. Shampine and  M. K.
     Gordon.

     Example:


































     //
     //  Integrate the Van der Pol equation, and measure the effect
     //  of relerr and abserr on the solution.
     //

     vdpol = function ( t , x )
     {
       xp = zeros(2,1);
       xp[1] = x[1] * (1 - x[2]^2) - x[2];
       xp[2] = x[1];
       return xp;
     };

     t0 = 0;
     tf = 10;
     x0 = [0; 0.25];
     dtout = 0.05;

     relerr = [1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1];
     abserr = relerr;

     //
     //  Baseline
     //

     xbase = ode( vdpol, 0, 20, x0, 0.05, 1e-9, 1e-9);
     results = zeros (relerr.n, abserr.n);
     elapse = zeros (relerr.n, abserr.n);

     //
     // Now loop through the combinations of relerr
     // and abserr, saving the results, and computing
     // the maximum difference.
     //
             "start testing loop"
     for (i in 1:abserr.n)
     {
       xode.[i] = <<>>;
       for (j in 1:relerr.n)
       {
         printf("\t%i %i\n", i, j);
         tic();
         xode.[i].[j] = ode( vdpol, 0, 20, x0, 0.05, relerr[j], abserr[i]);
         elapse[i;j] = toc();

         // Save results
         results[i;j] = max (max (abs (xode.[i].[j] - xbase)));
       }
     }

     > results
      results =
      matrix columns 1 thru 6
      1.97e-05   0.000297   0.000634    0.00815      0.078       1.44
      0.000128   7.89e-05   0.000632    0.00924     0.0732       1.61
      0.000647   0.000625    0.00112     0.0147     0.0995       1.46
       0.00355    0.00352    0.00271     0.0118     0.0883      0.862
        0.0254     0.0254     0.0254      0.104      0.218       1.72
         0.513      0.513      0.513      0.589      0.467       1.82






     Each row of results is a function of the absolute error (abserr)
     and each column is a function of the relative error (relerr).


     SSeeee AAllssoo
        ode4





























































