I am trying to get the fixed points for the tent equation. With the given initial conditions, the solution must be 0.6. Everything works fine when I use float for x0, but when I define x0 as a double, the solution changes to 0.59999 in 55th iteration, which causes further changes in the next iteration and so on. Why is there such a difference while choosing the data types?
using namespace std;
#include <iostream>
main()
{
double x0=.6;
for (int i=0;i<100;i++)
{
if(x0<.5)
x0=1.5*x0;
else
x0=1.5*(1-x0);
cout << i << "\t" << x0 << endl;
}
}
I have posted an image of the results. Comparison of solutions - Float and Double