Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> def f(x): return x**2-2 >>> NR(f, diff_param(f),, x0=10) SyntaxError: invalid syntax >>> NR(f, diff_param(f), x0=10) 10 98 5.1002449877490195 24.012498935058996 2.746422262566088 5.5428352443186295 1.737504878944583 1.0189232043562302 1.4443747454506253 0.08621840529555858 1.4145388009969504 0.0009200195258900479 1.4142137146723768 4.307674426051733e-07 1.41421356242693 1.5226842009496977e-10 convergence in 7 iterations 1.41421356242693 >>> NR(f, diff_param(f), x0=1) 1 -1 1.4997501249376068 0.24925043725036744 1.416680497711029 0.006983632594768974 1.4142165798805022 8.53480890494751e-06 1.4142135634427837 3.0255362659659113e-09 convergence in 4 iterations 1.4142135634427837 >>> NR(f, diff_param(f), x0=-1) -1 -1 -1.5002501250625102 0.25075043775007755 -1.4166527198815504 0.006904928747794692 -1.4142148017633787 3.5055266325301204e-06 -1.4142135619352931 -1.2382908032293471e-09 convergence in 4 iterations -1.4142135619352931 >>> NR(f, diff_param(f), x0=-10) -10 98 -5.099754987745549 24.00750093503561 -2.7457345482186373 5.5390582092814045 -1.7368848284605043 1.0167689073362753 -1.444101543709638 0.0854292685445599 -1.4145126073037397 0.0008459162212237636 -1.4142134882517403 -2.096468447732036e-07 -1.4142135623993122 7.415312808234376e-11 convergence in 7 iterations -1.4142135623993122 >>> NR(f, diff_param(f), x0=2**0.5) 1.4142135623730951 4.440892098500626e-16 convergence in 0 iterations 1.4142135623730951 >>> NR(f, diff_param(f), x0=0) 0 -2 2000.0000001645333 3999998.000658133 1000.0007500599238 999999.5001204102 500.00162500338405 249999.6250060247 250.0030624847886 62499.53125177311 125.00578118605546 15624.445329935977 62.51114019000469 3905.6426478544195 31.27181711355093 975.9265455833769 15.66813571637503 243.49047682674686 7.898139616063236 60.380609394827516 4.075923871974011 14.61315541012761 2.2835249619157834 3.21448625169248 1.57983601251894 0.49588182645174417 1.4229447493560359 0.024771759719911746 1.414243407160942 8.441469818976088e-05 1.4142135732356653 3.072398868653181e-08 1.414213562376934 1.0858425270043881e-11 convergence in 16 iterations 1.414213562376934 >>> f(0) -2 >>> diff_param(f)(0) 0.0009999999999177334 >>> diff_param(f, h = 10**-8)(0) 0.0 >>> diff_param(f, h = 10**-8)(0)NR(f, diff_param(f), x0=0) SyntaxError: invalid syntax >>> NR(f, diff_param(f)) -87.85648009720302 7716.76109507023 -43.939372311853305 1928.668439159661 -21.99219504395522 481.6566428513686 -11.041319227247422 119.91073027798362 -5.610982591441601 29.48312564146071 -2.9834790602456356 6.901147302924182 -1.8267248283946043 1.3369235986732964 -1.4606900505604123 0.1336154238061802 -1.4149372994870508 0.002047561479708193 -1.4142134916942095 -1.999100720517788e-07 -1.4142135623980945 7.070921625995652e-11 convergence in 10 iterations -1.4142135623980945 >>> def g(x): 2*x >>> g(0) >>> def g(x): return 2*x >>> g(0) 0 >>> NR(f, g, x0=0) zero derivative, x0= 0 i= 0 xi= 0 >>> NR(f, lambda x:2*x, x0=0) zero derivative, x0= 0 i= 0 xi= 0 >>> def h(x = uniform(0,10)): return x >>> h() 9.937876864702076 >>> h(5) 5 >>> h() 9.937876864702076 >>> h() 9.937876864702076 >>>