next up previous
Next: On the ``automatically generated'' Up: Running Taylor Previous: Overall

Example 1

Let's save the next four lines in the ASCII file lorenz.eq1. It specifies the famous Lorenz equation.

       RR  = 28.0;
       diff(x,t) = 10.0* (y - x);
       diff(y,t) = RR * x - x*z - y;
       diff(z,t) = x* y - 8.0* z /3.0;

After saving the file lorenz.eq1, let's ask taylor to generate a solver for us. A first possibility is to invoke taylor as follows

   taylor -name lrnz -o lorenz.c -jet -step lorenz.eq1
   taylor -name lrnz -o taylor.h -header
The first line creates the file lorenz.c (-o flag) with the code that computes the jet of derivatives (-jet flag) and the step size control (-step flag); the ODE description is read from the input file lorenz.eq1. The flag -name is to tell taylor the name we want for the function that performs a single step of the numerical integration; in this case the name is taylor_step_lrnz (the string after the -name flag is appended to the string taylor_step_ to get the name of this function). The detailed description of the parameters of this function is in Section 5.3. The second line produces a header file (named taylor.h) needed to compile lorenz.c, that also contains the prototypes of the functions in lorenz.c (this is the reason for using again the flag -name) so the user may also want to include it to have these calls properly declared. As we have not specified the kind of arithmetic we want, this header file will use the standard double precision of the computer.

Then, the user only needs to call this integration routine to compute a sequence of points on a given orbit - this is similar to the standard use of most numerical integrators, like Runge-Kutta or Adams-Bashford.

As an example, let us ask taylor to create a very simple main program for the Lorenz system,

   taylor -name lrnz -o main_lrnz.c -main_only lorenz.eq1
Now we can compile and link these files,
   gcc -O3 main_lrnz.c lorenz.c -lm -s
to produce a binary that will ask us for an initial condition and will print a table of values of the corresponding orbit to the screen. A look at this main program will give you an idea of how to call the Taylor integrator.

There are other ways of invoking taylor. For instance,

   taylor -o lorenz.c lorenz.eq1
produces a single output file lorenz.c that includes the header file, a small main program, the step size control code and the function to compute the jet of derivatives. In this sense, lorenz.c contains a full program ready to be compiled and run:
   gcc -O3 lorenz.c -lm
If we run the binary (a.out), the output looks like
    Enter Initial xx[0]: 0.1
    Enter Initial xx[1]: 0.2
    Enter Initial xx[2]: 0.3
    Enter start time: 0.0
    Enter stop time: 0.3
    Enter absolute error tolerance: 0.1e-16
    Enter relative error tolerance: 0.1e-16

    0.1      0.2      0.3      0.0
    0.166068 0.355113 0.266465 0.0467065
    0.296904 0.643972 0.238433 0.0968925
    0.508526 1.10588  0.225988 0.142787
    0.823022 1.79068  0.239631 0.18375
    1.26605  2.75389  0.299485 0.220385
    1.86192  4.04596  0.440512 0.253231
    2.63611  5.71608  0.718778 0.282924
    3.21698  6.96047  0.995948 0.3
The output of a.out are the values of the state variables, in the order as they appear in the input file, plus the value of the time variable. For our last example, each row of the output are values of x, y, z and t.