예제 #1
0
파일: multiroots.py 프로젝트: pygsl/pygsl
def run_fdfsolver():
    params = numx.array((1., 10.), )
    mysys = multiroots.gsl_multiroot_function_fdf(rosenbrock_f, rosenbrock_df,
                                                  rosenbrock_fdf, params, 2)

    #solver = multiroots.newton(mysys, 2)
    solver = multiroots.gnewton(mysys, 2)
    #solver = multiroots.hybridj(mysys, 2)
    #solver = multiroots.hybridsj(mysys, 2)

    tmp = numx.array((-10., -5.), )
    solver.set(tmp)
    print "# Testing solver ", solver.name()
    print "# %5s %9s %9s  %9s  %10s" % ("iter", "x[0]", "x[1]", "f[0]", "f[1]")
    for iter in range(100):
        status = solver.iterate()
        r = solver.root()
        x = solver.getx()
        f = solver.getf()
        status = multiroots.test_residual(f, 1e-7)
        if status == errno.GSL_SUCCESS:
            print "# Converged :"
        print "  %5d % .7f % .7f  % .7f  % .7f" % (iter, x[0], x[1], f[0],
                                                   f[1])
        if status == errno.GSL_SUCCESS:
            break
    else:
        raise ValueError, "Number of Iterations exceeded!"
예제 #2
0
def run_fdfsolver():
    params = numx.array((1., 10.),)
    mysys = multiroots.gsl_multiroot_function_fdf(rosenbrock_f, rosenbrock_df,
                                                  rosenbrock_fdf, params, 2)
    
    #solver = multiroots.newton(mysys, 2)
    solver = multiroots.gnewton(mysys, 2)
    #solver = multiroots.hybridj(mysys, 2)
    #solver = multiroots.hybridsj(mysys, 2)
    
    tmp = numx.array((-10., -5.), )
    solver.set(tmp)
    print "# Testing solver ", solver.name() 
    print "# %5s %9s %9s  %9s  %10s" % ("iter", "x[0]", "x[1]", "f[0]", "f[1]")
    for iter in range(100):
        status = solver.iterate()
        r = solver.root()
        x = solver.getx()
        f = solver.getf()
        status = multiroots.test_residual(f, 1e-7)
        if status == errno.GSL_SUCCESS:
            print "# Converged :"
        print "  %5d % .7f % .7f  % .7f  % .7f" %(iter, x[0], x[1], f[0], f[1])
        if status == errno.GSL_SUCCESS:
            break
    else:
        raise ValueError, "Number of Iterations exceeded!"
예제 #3
0
    def _run(self, solver):
        tmp = Numeric.array((-10., -5.), Float)
        solver.set(tmp)
        for iter in range(100):
            status = solver.iterate()
            r = solver.root()
            x = solver.getx()
            f = solver.getf()
            status = multiroots.test_residual(f, 1e-7)
            if status == 0:
                break
        else:
            raise ValueError("Number of Iterations exceeded!")

        assert (Numeric.absolute(x[0] - 1) < 1e-6)
        assert (Numeric.absolute(x[1] - 1) < 1e-6)
        assert (Numeric.absolute(f[0]) < 1e-6)
        assert (Numeric.absolute(f[1]) < 1e-6)
예제 #4
0
 def _run(self, solver):
     tmp = Numeric.array((-10., -5.), Float)
     solver.set(tmp)
     for iter in range(100):
         status = solver.iterate()
         r = solver.root()
         x = solver.getx()
         f = solver.getf()
         status = multiroots.test_residual(f, 1e-7)
         if status == 0:
             break
     else:
         raise ValueError, "Number of Iterations exceeded!"
 
     assert(Numeric.absolute(x[0] - 1)<1e-6)
     assert(Numeric.absolute(x[1] - 1)<1e-6)
     assert(Numeric.absolute(f[0])<1e-6)
     assert(Numeric.absolute(f[1])<1e-6)