#include // Parameters of the Lorenz equation const double S = 10.0; // Sigma const double R = 100.0; // Rho const double B = 5.0; // Beta // Parameters to solve the equation numerically const double DT = 1.0E-5; // Time-step for each cycle const double TIME_MAX = 8.0; // The rough end-time to quit the computation const long long int LOOPS = static_cast(TIME_MAX / DT); // End count of loops // Parameters for outputting data const long long int OUTPUT_POINTS = 2400LL; // The rough number of points to plot const long long int OUTPUT_INTERVAL = LOOPS / OUTPUT_POINTS; // Interval to output data in the loop // Note: // For keeping code simpler, // the actual end-time and the actual number of points on the graph // may be different with the above specified values in some extent. // If you want to control them exactly, please customize code yourself. // Coordinate variables and initial values double x = 0.1; double y = 0.1; double z = 0.1; // The function giving the time-derivative of the x coordinate: dx/dt double dxdt(double x, double y, double z){ return -S*x + S*y; } // The function giving the time-derivative of the y coordinate: dy/dt double dydt(double x, double y, double z){ return -x*z + R*x - y; } // The function giving the time-derivative of the z coordinate: dz/dt double dzdt(double x, double y, double z){ return x*y - B*z; } // ================================================================================ // Solve the differential equation by using Runge-Kutta 4th order (RK4) method // ================================================================================ int main() { for( long long int i=0; i