ode:

Syntax:	ode ( rhsf, tstart, tend, ystart, dtout, relerr, abserr )

Synopsis:       Integrate a system of first order differential
	        equations. 

Description:

        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:

        rhsf    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 ) 
                {
                  local (xp)
                  xp = zeros(2,1);
                  xp[1] = x[1] * (1 - x[2]^2) - x[2];
                  xp[2] = x[1];
                  return xp;
                };

	ystart	The initial values of y, y(tstart).

        tstart  The initial value of the independent variable.

        tend    The final value of the independent variable.

        dtout   The output interval. The vector y will be saved at
                tstart, increments of tstart + dtout, and tend. If
                dtout is not specified, then the default is to store
                output at 101 values of the independent variable.

        relerr  The relative error tolerance. Default value is 1.e-6.

        abserr  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.


	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 ) 
	{
	  local (xp)
	  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, x0, 0, 20, 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, x0, 0, 20, 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).


See Also: ode4
