Difference between revisions of "CS382:Attractor inC"

From Earlham CS Department
Jump to navigation Jump to search
Line 1: Line 1:
{
+
\#include "stdio.h"
#include "stdio.h"
+
\#include "stdlib.h"
#include "stdlib.h"
+
\#include "math.h"
#include "math.h"
 
  
#define N 10000
+
\#define N 10000
  
 
int main(int argc,char **argv)
 
int main(int argc,char **argv)
Line 28: Line 27:
 
         printf("%d %g %g %g\n",i,x0,y0,z0);
 
         printf("%d %g %g %g\n",i,x0,y0,z0);
 
   }
 
   }
}
 
 
}
 
}

Revision as of 09:33, 15 April 2009

\#include "stdio.h" \#include "stdlib.h" \#include "math.h"

\#define N 10000

int main(int argc,char **argv) {

  int i=0;
  double x0,y0,z0,x1,y1,z1;
  double h = 0.01;
  double a = 10.0;
  double b = 28.0;
  double c = 8.0 / 3.0;
  x0 = 0.1;
  y0 = 0;
  z0 = 0;
  for (i=0;i<N;i++) {
     x1 = x0 + h * a * (y0 - x0);
     y1 = y0 + h * (x0 * (b - z0) - y0);
     z1 = z0 + h * (x0 * y0 - c * z0);
     x0 = x1;
     y0 = y1;
     z0 = z1;
     if (i > 100)
        printf("%d %g %g %g\n",i,x0,y0,z0);
  }

}