Exemplo n.º 1
0
def test_solve():
    def f(x, i):
        return [x[0] + (x[0] - x[1])**3/2 - 1,
                (x[1] - x[0])**3/2 + x[1]], i

    def j(x):
        return [
            [
                1 + 3/2 * (x[0] - x[1])**(3-1),
                -3/2 * (x[0] - x[1])**(3-1)
            ],
            [
                -3/2 * (x[1] - x[0])**(3-1),
                1 + 3/2 * (x[1] - x[0])**(3 - 1)
            ]
        ]

    x, ierr = solve(f, j, [0, 1])
    assert abs(x[0] - 0.8411639) < 2e-7
    assert abs(x[1] - 0.1588361) < 2e-7
Exemplo n.º 2
0
    def _solve_nleq2(self, intern_x0, tol=1e-8, method=None, **kwargs):
        """ Provisional, subject to unnotified API breaks """
        from pynleq2 import solve

        def f_cb(x, ierr):
            f_cb.nfev += 1
            return self.f_callback(x, self.internal_params), ierr
        f_cb.nfev = 0

        def j_cb(x, ierr):
            j_cb.njev += 1
            return self.j_callback(x, self.internal_params), ierr
        j_cb.njev = 0

        x, ierr = solve(f_cb, j_cb, intern_x0, **kwargs)
        return {
            'x': x,
            'fun': np.asarray(f_cb(x, 0)),
            'success': ierr == 0,
            'nfev': f_cb.nfev,
            'njev': j_cb.njev,
            'ierr': ierr,
        }
Exemplo n.º 3
0
    def _solve_nleq2(self, intern_x0, tol=1e-8, method=None, **kwargs):
        """ Provisional, subject to unnotified API breaks """
        from pynleq2 import solve

        def f_cb(x, ierr):
            f_cb.nfev += 1
            return self.f_cb(x, self.internal_params), ierr
        f_cb.nfev = 0

        def j_cb(x, ierr):
            j_cb.njev += 1
            return self.j_cb(x, self.internal_params), ierr
        j_cb.njev = 0

        x, ierr = solve(f_cb, j_cb, intern_x0, **kwargs)
        return {
            'x': x,
            'fun': np.asarray(f_cb(x, 0)),
            'success': ierr == 0,
            'nfev': f_cb.nfev,
            'njev': j_cb.njev,
            'ierr': ierr,
        }