Example #1
0
File: roots.py Project: pygsl/pygsl
def run_fdfsolver():
    a = 1.0
    b = 0.0
    c = -5.0
    mysys = roots.gsl_function_fdf(quadratic, quadratic_deriv, quadratic_fdf,
                                   numx.array((a, b, c)))

    solver = roots.newton(mysys)
    #solver = roots.secant(mysys)
    #solver = roots.steffenson(mysys)

    x = 5.0
    solver.set(x)
    r_expected = numx.sqrt(5.0)
    print "# Using solver ", solver.name()
    print "# %5s %9s  %10s %9s" % ("iter", "root", "err", "err(est)")
    ok = 1
    for iter in range(10):
        status = solver.iterate()
        x0 = x
        x = solver.root()
        status = roots.test_delta(x, x0, 0.0, 1e-3)
        r = solver.root()
        if status == errno.GSL_SUCCESS:
            print "#  Convereged :"
        print "%5d  %.7f  % .6f % .6f" % (iter, r, r - r_expected, x - x0)
        if status == errno.GSL_SUCCESS:
            break
    else:
        raise ValueError, "Exeeded maximum number of iterations!"
Example #2
0
 def setUp(self):
     a = 1.0
     b = 0.0
     c = -5.0
     self.sys = roots.gsl_function_fdf(quadratic, quadratic_deriv,
                                       quadratic_fdf,
                                       Numeric.array((a, b, c)))
Example #3
0
def run_fdfsolver():    
    a = 1.0
    b = 0.0
    c = -5.0
    mysys = roots.gsl_function_fdf(quadratic, quadratic_deriv, quadratic_fdf,
                                 numx.array((a,b,c)))

    solver = roots.newton(mysys)    
    #solver = roots.secant(mysys)
    #solver = roots.steffenson(mysys)

    x = 5.0
    solver.set(x)
    r_expected = numx.sqrt(5.0)
    print "# Using solver ", solver.name() 
    print "# %5s %9s  %10s %9s" % ("iter", "root", "err", "err(est)")
    ok = 1
    for iter in range(10):
        status = solver.iterate()
        x0 = x
        x = solver.root()
        status = roots.test_delta(x, x0, 0.0, 1e-3)
        r = solver.root()
        if status == errno.GSL_SUCCESS:
            print "#  Convereged :"
        print "%5d  %.7f  % .6f % .6f" %(iter, r, r -r_expected, x - x0)
        if status == errno.GSL_SUCCESS:
                break
    else:
        raise ValueError, "Exeeded maximum number of iterations!"
Example #4
0
 def setUp(self):
     a = 1.0
     b = 0.0
     c = -5.0
     self.sys = roots.gsl_function_fdf(quadratic, quadratic_deriv, quadratic_fdf, Numeric.array((a,b,c)))