This program was used to create all of the non-quantized images of the lorenz attractor in this document. It simply acts as a functional flat file creation mechanism, generating output in row, column format.
#include <stdio.h> #include <stdlib.h> #include <math.h> #define TIMESTEP 0.0001 /* Numerical timestep for dt */ #define XSCALE 4 /* Appropriate scaling factors for */ #define YSCALE 4 /* each axis. */ #define ZSCALE 4 #define TSCALE 20 /* Scaling factor for the time axis */ #define INTERVAL 100 /* Sample function every INTERVAL points for output */ void main() { double x1, y1, z1, x, y, z, t, dt, t0=0.0; FILE *file, *file2, *file3, *file4; file=fopen("output", "w"); /* Holds x-z plane view of attractor */ file2=fopen("x", "w"); /* x versus time */ file3=fopen("y", "w"); /* y versus time */ file4=fopen("z", "w"); /* z versus time */ x1=(y1=(z1=(t=0.0001))); /* Initial conditions */ dt=TIMESTEP; while((t*TSCALE)<639.0) { x=x1 + ( -10.0*x1 + 10.0*y1 ) * dt; /* Solve system numerically */ y=y1 + ( 28.0*x1 - y1 - x1*z1 ) * dt; z=z1 + ( -(8/3)*z1 + x1*y1 ) * dt; t=t + dt; if (t>=(t0+INTERVAL*TIMESTEP)) /* Write output to files */ { fprintf(file, "%f %f\n", x, z); fprintf(file2, "%f %f\n", t, x); fprintf(file3, "%f %f\n", t, y); fprintf(file4, "%f %f\n", t, z); t0=t; } x1=x; y1=y; z1=z; } fclose(file); fclose(file2); fclose(file3); fclose(file4); }