Hey:
I am kinda new to C++. I created this code to display the edge of chaos. Now my professor wants me to graph it in a coordinate system. I know I could use excel and plot it there but I want to learn how to do it using C++. Does anyone knows how ?
Thanks,
G
Here is the code
#include <fstream>
#include <cmath> //for fabs, log
using namespace std;
int main(void)
{
ofstream data("lambda.doc");
int T = 10000; //numbver of iterations
double x = 0.618; //initial value
double x1;
double eps = 0.0005;
double xeps = x-eps;
double xeps1;
double r = 3.0;
double sum = 0.0;
while(r <= 4.0)
{
for(int t=0;t<T;t++)
{
x1 = x;
x = r*x1*(1.0-x1);
double distance = fabs(x-xeps);
sum += log(distance/eps);
xeps = x-eps;
}
double lambda = sum/((double)T);
data << r << " " << lambda << "\n";
sum = 0.0;
r += 0.001;
} //end while
data.close();
return 0;
}