;ò
…Rã?c           @   sµ   d  „  Z  d „  Z d „  Z d „  Z d d d „ Z e d j oq d k l Z l Z d	 GHe e d
 d f d d ƒZ	 e  e d
 d f d ƒ Z
 d Z d	 GHd Ge
 GHd e GHd	 GHn d S(   c         C   sx   | \ } } t | | ƒ | } d |  | ƒ |  | ƒ } x/ t d | ƒ D] } | |  | | | ƒ } qJ W| | Sd S(   s­  Returns the integral of |function| (a function of one variable)
    over |interval| (a sequence of length two containing the lower and
    upper limit of the integration interval), calculated using the
    trapezoidal rule using |numtraps| trapezoids.

    Example:

      >>>from Scientific.Functions.Romberg import romberg
      >>>from Numeric import pi
      >>>romberg(tan, (0.0, pi/3.0))

      yields '0.693147180562'
    f0.5i   N(
   s   intervals   loxs   hixs   floats   numtrapss   hs   functions   sums   ranges   i(   s   functions   intervals   numtrapss   hixs   hs   sums   is   lox(    (    sG   /mit/python/lib/python2.3/site-packages/Scientific/Functions/Romberg.pys	   trapezoid
   s      c         C   sÃ   | d j o d GHd  Sn¦ | d j o$ d |  | d ƒ |  | d ƒ Snu | d } t | d | d ƒ | } | d d | } d } x/ t d | ƒ D] } | |  | | | ƒ } q™ W| Sd  S(   Ni    s#   numtraps must be > 0 in difftrap().i   f0.5i   f0.0(
   s   numtrapss   functions   intervals   numtosums   floats   hs   loxs   sums   ranges   i(   s   functions   intervals   numtrapss   is   hs   sums   numtosums   lox(    (    sG   /mit/python/lib/python2.3/site-packages/Scientific/Functions/Romberg.pys   difftrap   s    $
 c         C   s"   d | } | | |  | d Sd  S(   Nf4.0f1.0(   s   ks   tmps   cs   b(   s   bs   cs   ks   tmp(    (    sG   /mit/python/lib/python2.3/site-packages/Scientific/Functions/Romberg.pys   romberg_diff8   s    
c         C   sÞ   d } } d G|  Gd G| GHd GHd d d d f GHxp t t | ƒ ƒ D]\ } d	 d
 | | d | d | d f Gx( t | d ƒ D] } d | | | Gqƒ Wd GHqF Wd GHd G| | | Gd Gd
 t | ƒ d d Gd GHd  S(   Ni    s   Romberg integration ofs   froms    s   %6s %9s %9ss   Stepss   StepSizes   Resultss   %6d %9fi   i   f1.0s   %9fs   The final result iss   afters   function evaluations.(   s   is   js   functions   intervals   ranges   lens   resmat(   s   functions   intervals   resmats   js   i(    (    sG   /mit/python/lib/python2.3/site-packages/Scientific/Functions/Romberg.pys   printresmat>   s    
		 & 	f9.9999999999999995e-08i    c         C   sT  d } } | d | d } t |  | | ƒ } | | } | g g }
 | | d }	 xÜ t | |	 ƒ | j oÄ | d } | t |  | | ƒ } |
 i g  ƒ |
 | i | | | ƒ xI t | ƒ D]; } |
 | i t |
 | d | |
 | | | d ƒ ƒ q¿ W|
 | | } |
 | d | d }	 | d } qU W| o t |  | |
 ƒ n | Sd S(   sS  Returns the integral of |function| (a function of one variable)
    over |interval| (a sequence of length two containing the lower and
    upper limit of the integration interval), calculated using
    Romberg integration up to the specified |accuracy|. If |show| is 1,
    the triangular array of the intermediate results will be printed.i   i    f2.0i   N(   s   is   ns   intervals   intranges   difftraps   functions   ordsums   results   resmats   accuracys
   lastresults   abss   appends   ranges   ks   romberg_diffs   shows   printresmat(   s   functions   intervals   accuracys   shows   is   ks   ns   intranges   results
   lastresults   resmats   ordsum(    (    sG   /mit/python/lib/python2.3/site-packages/Scientific/Functions/Romberg.pys   rombergN   s.     

 
  s   __main__(   s   tans   pis    f0.5f1.0s   showi   iè  f0.48504222994229101s2   Trapezoidal rule with 1000 function evaluations  =s:   Theoretical result (correct to all shown digits) = %15.14fN(   s	   trapezoids   difftraps   romberg_diffs   printresmats   rombergs   __name__s   maths   tans   pis   rs   ts   theo(
   s   theos   printresmats   rombergs   difftraps   romberg_diffs   rs   ts	   trapezoids   tans   pi(    (    sG   /mit/python/lib/python2.3/site-packages/Scientific/Functions/Romberg.pys   ?
   s   						