;ò
…Rã?c           @   s“   d  k  l Z d „  Z e d j ol d k l Z l Z l Z d „  Z e e d d d ƒ Z	 d Z
 d	 GHd
 GHd GHd	 GHd Ge	 GHd e
 GHd	 GHn d S(   (   s   DerivVarc         C   s\  d } |  t | ƒ ƒ } | d } |  t | ƒ ƒ } | d } | d j o
 | d j p | d j  o
 | d j  o d GHt Sn | d j o | Sn | d j o | Sn | d j  o | } | }	 n | }	 | } d | | } t | | ƒ } | } |  t | ƒ ƒ } | d } | d d }
 x,t | ƒ D]} | |	 |
 | | | |
 | d j p t d | ƒ t | |
 ƒ j o7 | } d |	 | } | | } | | j o | Sqén6 | } | |
 } | } | | } | | j o | Sn t | ƒ | j  o | Sn |  t | ƒ ƒ } | d } | d d }
 | d j  o
 | } q-| }	 q-Wd GHd Sd	 S(
   s�  Finds the root of |function| which is bracketed by values
    |lox| and |hix| to an accuracy of +/- |xacc|. The algorithm
    used is a safe version of Newton-Raphson (see page 366 of NR in
    C, 2ed). |function| must be a function of one variable, and may
    only use operations defined for the DerivVar objects in the
    module FirstDerivatives.

    Example:

      >>>from Scientific.Functions.FindRoot import newtonRaphson
      >>>from Numeric import pi, sin, cos
      >>>def func(x):
      >>>    return (2*x*cos(x) - sin(x))*cos(x) - x + pi/4.0
      >>>newtonRaphson(func, 0.0, 1.0, 1.0e-12)

      yields '0.952847864655'.
    iô  i    f0.0s)   Root must be bracketed in newtonRaphson()f0.5i   f2.0s8   Maximum number of iterations exceeded in newtonRaphson()N(   s   maxits   functions   DerivVars   loxs   tmps   fls   hixs   fhs   Nones   xls   xhs   rtss   abss   dxolds   dxs   fs   dfs   ranges   js   temps   xacc(   s   functions   loxs   hixs   xaccs   tmps   dxs   xls   fs   js   xhs   dfs   maxits   temps   rtss   fhs   fls   dxold(    (    sH   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FindRoot.pys   newtonRaphson   s`     

4  

 J
 

  


s   __main__(   s   pis   sins   cosc         C   s6   d |  t |  ƒ t |  ƒ t |  ƒ |  t d Sd  S(   Ni   f4.0(   s   xs   coss   sins   pi(   s   x(    (    sH   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FindRoot.pys   funcT   s    f0.0f1.0f9.9999999999999998e-13f0.95284786465494198s    s*   Finding the root (between 0.0 and 1.0) of:s/       (2*x*cos(x) - sin(x))*cos(x) - x + pi/4 = 0s2   Safe-style Newton-Raphson gives (xacc = 1.0e-12) =s:   Theoretical result (correct to all shown digits) = %15.14fN(   s   FirstDerivativess   DerivVars   newtonRaphsons   __name__s   Numerics   pis   sins   coss   funcs   rs   theo(   s   theos   coss   rs   DerivVars   funcs   newtonRaphsons   pis   sin(    (    sH   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FindRoot.pys   ?
   s   	D			