Rekurzió $\pi$ meghatározására


In [1]:
%pylab inline
from ipywidgets import interact

def fun(n):
    a=sqrt(2)
    for i in range(1,n):
        a=sqrt((1-sqrt(1-a**2/4))**2+a**2/4)
    return a*2**n
phi=linspace(0,pi/2,60)
figsize(8,8)

def geo(m=0):
    plot([0,0,1],[1,0,0],color='black')
    plot(cos(phi),sin(phi),lw=25,color='black')
    p=linspace(0,pi/2,2**m+1)
    plot([0,0,cos(p[1])],[1,0,sin(p[1])],color='black')
    plot(cos(p[0::2]),sin(p[0::2]),'--',lw=4,color='gray')
    plot(cos(p),sin(p),'o-',lw=8,color='red',ms=20,mec='red')
    #
    axes().set_aspect('equal')
    xlim(-0.1,1.1)
    ylim(-0.1,1.1)
    axis('off');
    #
    text(0.7,0.95,r'$\pi/2=$'+str(pi/2),fontsize=50)
    text(0.7,0.8,r'$\;\,s=$'+str(fun(m+1)/2),fontsize=50,color='red')
    if m==1:
        text(0.5,-0.1,r'$1$',fontsize=50)
        text(-0.1,0.5,r'$1$',fontsize=50)
        text(0.5,0.6,r'$x$',fontsize=50)
        text(0.1,0.35,r'$1-x$',fontsize=50)
        text(0.5,0.2,r'$\frac{a_{m-1}}{2}$',fontsize=50)
        text(0.9,0.35,r'$a_m$',fontsize=50,color='red')
        text(1.2,0.5,r'$a^2_{m-1}/4+(1-x)^2=1$',fontsize=50)
        text(1.2,0.3,r'$a^2_{m-1}/4+x^2=a^2_m$',fontsize=50)
        text(1.2,0.1,r'$s=2^m a_m$',fontsize=50,color='red')
    elif m==10:
        text(1.1,0.4,r'$\lim_{m\rightarrow\infty} \left (2^m a_m\right)=\pi/2 $',fontsize=60,color='magenta')


Populating the interactive namespace from numpy and matplotlib

In [2]:
interact(geo,m=(0,17));



In [ ]: