コード例 #1
0
 def check_3(self,f=f1,per=0,s=0,a=0,b=2*pi,N=20,xb=None,xe=None,
           ia=0,ib=2*pi,dx=0.2*pi):
     if xb is None: xb=a
     if xe is None: xe=b
     x=a+(b-a)*arange(N+1,dtype=float)/float(N)    # nodes
     v=f(x)
     nk=[]
     put("  k  :     Roots of s(x) approx %s  x in [%s,%s]:"%\
           (f(None),repr(round(a,3)),repr(round(b,3))))
     for k in range(1,6):
         tck=splrep(x,v,s=s,per=per,k=k,xe=xe)
         roots = sproot(tck)
         if k == 3:
             assert_allclose(roots, pi*array([1, 2, 3, 4]),
                             rtol=1e-3)
         put('  %d  : %s'%(k,repr(roots.tolist())))