I have to do it in C++. I was supposed to do it in CERN's ROOT, but I got permission to use any other C++ program.
I am doing the logistics map where r varies from 1 to 4 in 2000 steps. However, in each step, it will iterate 300 times. So, r= 1 will iterate 300 times, then 1.0005 will iterate 300 times etc. 6000 iterations.
The y axis will give me the calculation for each iteration, and the x axis will be r from 1 t 4.
I was supposed to drop this class, so I missed a few lectures, but they didn't drop me, so I have to figure all this out.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <random>
#include <ctime>
usingnamespace std;
// Random number generator
mt19937 gen( time( 0 ) );
uniform_real_distribution<double> dist( 0.0, 1.0 );
double logistic( double r, double x, int n )
{
for ( int i = 0; i < n; i++ ) x = r * x * ( 1.0 - x );
return x;
}
int main()
{
double r1 = 1, r2 = 4; // limits on r
int N = 6000; // number of intervals for r
double dr = ( r2 - r1 ) / N;
int niter = 300; // number of iterations for each r
#define SP << fixed << setprecision( 6 ) << setw( 12 ) << // format of output
// ostream &out = cout; // output to screen
ofstream out( "logistic.out" ); // output to file
out SP "r" SP "x_end" << '\n'; // header
for ( int i = 0; i <= N; i++ )
{
double r = r1 + i * dr; // growth rate
double x0 = dist( gen ); // random starting point in (0,1)
out SP r SP logistic( r, x0, niter ) << '\n';
}
}
To be honest, I have no idea why I needed a 2d histogram. In my head, I pictured something completely different. I was supposed to drop this class, but they wouldn't let me, so I missed lectures. I am going off of the professor's lecture notes.