예제 #1
0
def test_success():
    f.calls = 0

    result = rootfinding.bracket_root(f, (0, -0.1))

    check_result(result, f, f_calls=f.calls, has_bracket=True, has_root=False)
    assert result.iterations >= 1
    rootfinding.bisect(f, result.bracket, f_bracket=result.f_bracket)
예제 #2
0
def test_instant2():
    bracket = (1, -1.00001)
    f_bracket = (f(bracket[0]), None)
    f.calls = 0

    result = rootfinding.bisect(f, bracket, f_bracket=f_bracket, maxiter=0)

    assert f.calls == 1
    check_result(result, f, f_calls=f.calls, has_bracket=True, has_root=True)
    assert result.root == 1
예제 #3
0
def test_growth_factor2():
    growth_factor = 3.14
    interval = (0, -0.1)
    f.calls = 0

    result = rootfinding.bracket_root(f, interval, growth_factor=growth_factor)

    check_result(result, f, f_calls=f.calls, has_bracket=True, has_root=False)

    assert result.bracket[1] - result.bracket[0] == pytest.approx(
        (interval[1] - interval[0]) * growth_factor**result.iterations)
예제 #4
0
def test_instantbracket():
    interval = (0, 2)
    f_interval = (None, f(interval[1]))
    f.calls = 0

    result = rootfinding.bracket_root(f,
                                      interval,
                                      f_interval=f_interval,
                                      maxiter=0)

    assert f.calls == 1
    check_result(result, f, f_calls=f.calls, has_bracket=True, has_root=False)
    rootfinding.bisect(f, result.bracket, f_bracket=result.f_bracket)
예제 #5
0
def test_success():
    ftol = 4 * sys.float_info.epsilon
    f.calls = 0

    result = rootfinding.bisect(f, (0.1, -1.5), ftol=ftol)

    check_result(result,
                 f,
                 ftol=ftol,
                 f_calls=f.calls,
                 has_bracket=True,
                 has_root=True)
    assert result.root == pytest.approx(-1)
예제 #6
0
def test_instantroot2():
    interval = (-1, 0)
    f_interval = (f(interval[0]), None)
    ftol = 0
    f.calls = 0

    result = rootfinding.bracket_root(f,
                                      interval,
                                      f_interval=f_interval,
                                      ftol=ftol,
                                      maxiter=0)

    assert f.calls == 1
    check_result(result,
                 f,
                 ftol=ftol,
                 f_calls=f.calls,
                 has_bracket=False,
                 has_root=True)
예제 #7
0
def test_instantrootwithbracket():
    interval = (0, -1.00001)
    f_interval = (f(interval[0]), None)
    ftol = 1e-3
    f.calls = 0

    result = rootfinding.bracket_root(f,
                                      interval,
                                      f_interval=f_interval,
                                      ftol=ftol,
                                      maxiter=0)

    assert f.calls == 1
    check_result(result,
                 f,
                 ftol=ftol,
                 f_calls=f.calls,
                 has_bracket=True,
                 has_root=True)
    rootfinding.bisect(f, result.bracket)