In [2]:
# plot strange attractor for the baker map
#
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
In [3]:
# I increased precission here!
from decimal import *
getcontext().prec = 10


# high precission version of pi  , cut and paste from Decimal doc website
def dv_pi():
        getcontext().prec += 2  # extra digits for intermediate steps
        three = Decimal(3)      # substitute "three=3.0" for regular floats
        lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24
        while s != lasts:
                lasts = s
                n, na = n+na, na+8
                d, da = d+da, da+32
                t = (t * n) / d
                s += t

        getcontext().prec -= 2
        return +s               # unary plus applies the new precision




d2 = Decimal(2.0)
d1 = Decimal(1.0)
In [7]:
# baker map function returns x,y
def baker(x,y,c):
        xout = d1 + c*(x-d1)
        yout = d1 + d2*(y-d1)
        if (y<=Decimal(0.5)):
                xout=c*x
                yout=d2*y

        #print(xout,yout)
        return xout,yout


def plotbaker(xi,yi,c,nit,ax):
        plt.plot(xi,yi)
        xout =xi
        yout =yi
        for i in range(0,nit):
                xout,yout  = baker(xout,yout,c)
                #print xout,yout
                ax.plot(xout,yout,'ro', markersize=1)
In [8]:
plt.figure()
fig,ax = plt.subplots(1,1,figsize=(3,3))
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlim([0.0, 1])
ax.set_ylim([0.0, 1])

x0=Decimal(0.5)
y0 = Decimal(2.0)/dv_pi()**2
o3 = Decimal(1.0)/Decimal(3.0)

plotbaker(x0,y0,o3,8000,ax)
<Figure size 640x480 with 0 Axes>
In [ ]: