/*************************************************************************************************************************************/ /* */ /* E T U D E D E S O P T I O N S D ' O P T I M I S A T I O N */ /* P O U R U N P S U D O - A T T R A C T E U R D E L O R E N Z */ /* ( C O N T E N A N T D E S T E R M E S E N ' x*y*z ' ) : */ /* */ /* */ /* Author of '$xtc/lorenz.21$c' : */ /* */ /* Jean-Francois COLONNA (LACTAMME, AAAAMMJJhhmmss). */ /* */ /*************************************************************************************************************************************/ #include <stdio.h> #define ITER 12701 #define PRECIS double \ /* Permet de travailler en 'double' ou en 'float'. */ #define DT 0.01 #define X0 0.01 #define Y0 0.01 #define Z0 0.01 main() { int n; PRECIS x1 = X0,dx1; PRECIS y1 = Y0,dy1; PRECIS z1 = Z0,dz1; PRECIS x2 = X0,dx2; PRECIS y2 = Y0,dy2; PRECIS z2 = Z0,dz2; PRECIS dt = DT; int print=1; for (n=1 ; n<=ITER ; n++) { if (print == 0) { printf("\n x1=%+10.6f y1=%+10.6f z1=%+10.6f",x1,y1,z1); printf("\n x2=%+10.6f y2=%+10.6f z2=%+10.6f",x2,y2,z2); } else { } dx1 = (-10.0*x1 + 10.0*y1 - 0.02*x1*y1*z1)*dt; dy1 = (28.0*x1 - y1 - x1*z1 + 0.01*x1*y1*z1)*dt; dz1 = ((-8.0 / 3.0)*z1 + x1*y1 + 0.01*x1*y1*z1)*dt; dx2 = -10.0*x2*dt + 10.0*y2*dt - 0.02*x2*y2*z2*dt; dy2 = 28.0*x2*dt - y2*dt - x2*z2*dt + 0.01*x2*y2*z2*dt; dz2 = (-8.0 / 3.0)*z2*dt + x2*y2*dt + 0.01*x2*y2*z2*dt; /* ATTENTION, il ne faut pas de parentheses et il est imperatif de ne pas mettre 'dt' en */ /* facteur commun et ce afin d'avoir des produits a 3 termes... */ x1 = x1 + dx1; y1 = y1 + dy1; z1 = z1 + dz1; x2 = x2 + dx2; y2 = y2 + dy2; z2 = z2 + dz2; } printf("\n 'dt' non distribue : iterations=%d x1=%+10.6f y1=%+10.6f z1=%+10.6f",n-1,x1,y1,z1); printf("\n 'dt' distribue : iterations=%d x2=%+10.6f y2=%+10.6f z2=%+10.6f",n-1,x2,y2,z2); /* Avec 'cc -O0', donne : */ /* */ /* 'dt' non distribue : iterations=12701 x1=-24.096380 y1= -8.203284 z1=+41.243466 */ /* 'dt' distribue : iterations=12701 x2= +4.641505 y2= +7.711528 z2=+19.545368 */ /* */ /* et avec 'cc -O3', donne : */ /* */ /* 'dt' non distribue : iterations=12701 x1= -6.589218 y1=-11.343677 z1=+10.877308 */ /* 'dt' distribue : iterations=12701 x2= -0.186530 y2= -0.543707 z2=+20.303556 */ /* */ /* ainsi grace aux termes en 'x*y*z', {x1,y1,z1} ('dt' non distribue), tout comme {x2,y2,z2} */ /* ('dt' distribue), depend de l'optimisation... */ printf("\n"); }