II.   Presentation of the program.

    The program I made allows to plot a black and white .ppm image file (this is an ascii file) showing the evolution in the phase diagram of the orbit of several points with different initial conditions. Here is the contents of the henon.c program :
 

/* To compile : gcc -o henon henon.c -lm */
/* To run : henon 10000*a 10000*b (a,b=x.xxxx) */
/* Exemple : henon 14000 3000 */

/* Libraries:*/
#include <stdio.h>
#include <math.h>

/* Definition of the size of the image*/
#define ROW 500
#define COL 500

/* Begin of the main program*/
main(int argc, char *argv[])
{
  /* definition of the variables*/
  int i,j,row,col,test=0;
  int val[ROW][COL];
  double k,a,b,x_one,y_one,temp_one,temp_two,x_plus_one,y_plus_one;
  FILE *ppm;

  /* Case where the number of parameters is not valid */
  if(argc!=3)
  {
    printf("Number of parameters not valid\n");
    printf("Syntax: henon a*10000 b*10000\nWith a and b, the 2 parameters\n");
    exit(1);
  }

  /* Initialisation of the picture */
  for(i=0;i<ROW;i++)
  {
    for(j=0;j<COL;j++)
    {
      val[i][j]=0;
    }
  }

  /* Reading the parameters */
  a=atoi(argv[1]);
  b=atoi(argv[2]);
  a/=10000;
  b/=10000;

  /* Begin of the calculation loop */
  for(k=0.1;k<1;k+=0.05)
    {

    /* initialisation of the parameters */
    x_one=k;
    y_one=0.0;

    for(i=0;i<100000;i++)
    {

      /* Calculation of the new point */
      x_plus_one=y_one+1-a*x_one*x_one;
      y_plus_one=b*x_one;

      /* Preparing the next calculation */
      x_one=x_plus_one;
      y_one=y_plus_one;

      /* Approximation of the new point in order to plot it */
      row=ceil((ROW*0.35*x_one+(ROW/2)));
      col=ceil((COL*0.35*y_one+(COL/2)));

      /* Case where the point doesn't enter the picture */
      if(row>=ROW)
      {
        test=1;
      }
      if(row<=0)
      {
        test=1;
      }
      if(col>=COL)
      {
        test=1;
      }
      if(col<=0)
      {
        test=1;
      }
      if(test==0)
      {
        val[row][col]=15;
      }
      test=0;
    }
  }

  /* Plot of the points in the img.ppm file */
  ppm=fopen("img.ppm","w");
  fprintf(ppm,"P3 \n");
  fprintf(ppm,"%d %d \n",ROW,COL);
  fprintf(ppm,"15  \n");
  for(i=0;i<ROW;i++)
  {
    for(j=0;j<COL;j++)
    {
      fprintf(ppm,"%d %d %d ",val[i][j],val[i][j],val[i][j]);
    }
  }

  /* Closing the ppm file */
  fclose(ppm);
  return(0);
}
 

   After a lot of hesitations, this program decided to run efficiently as the reader could see it in the third part of this report.
 

    Each step of this program is commented. To compile it, the line that has to be written on the Unix workstation is : gcc -o henon henon.c -lm    (-lm deals with the mathematic library).
The reader should have noticed that the two parameters (a and b) that have to be written after the executable "henon" command must be integers multiplied by the factor of precision needed. It's ugly but it works. I didn't manage to make the atof function (ascii to float) run correctly, that's why I had to use this trick. The .ppm file can be read with an image viewer (for example XV) and then can be saved with the format the user wants (.gif to insert in html files).
It is possible to change the parameters of the program in order to obtain more points by increasing the iteration number. It is also possible to increase the size of the window of the .ppm file by modifying the definition of ROW and COL (default is 500).  It is interesting in order to make zooms.
The next step of this report is now to use on concrete cases.
 
 

   Go to next page
   Go to previous page