コード例 #1
0
def test_sturm_q():
    x = var('x')

    p = x**3 - 7*x + 7
    q = 3*x**2 - 7
    assert sturm_q(p, q, x) == sturm(p)
    assert sturm_q(-p, -q, x) != sturm(-p)
コード例 #2
0
def test_sturm_q():
    x = var('x')

    p = x**3 - 7 * x + 7
    q = 3 * x**2 - 7
    assert sturm_q(p, q, x) == sturm(p)
    assert sturm_q(-p, -q, x) != sturm(-p)
コード例 #3
0
def partition(f, LB, UB):

    Sseq = sturm(f)
    print("sturm: \n", Sseq)

    sL = []
    [sL.append(Sseq[i].subs(x, LB)) for i in range(degree(f, x) + 1)]
    print('sL = ', sL, '\n')
    vsL = variations(sL)
    print('vsL = ', vsL, '\n')

    print("bounds using upperBound LMQ: ", UB, "\n")

    sR = []
    [sR.append(Sseq[i].subs(x, UB)) for i in range(0, degree(f, x) + 1)]
    print('sR = ', sR, '\n')
    vsR = variations(sR)
    print('vsR = ', vsR, '\n')

    number_of_roots = vsR - vsL

    print("THE NUMBER OF REAL ROOTS BETWEEN", LB, " AND ", UB, " IS: ",
          abs(number_of_roots))

    return abs(number_of_roots)
コード例 #4
0
ファイル: sturm.py プロジェクト: Yaffle/FloPoly
def test():
    #x = map(Symbol, ['x'])
    x = Symbol('x')

    P = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
    sP = sturm(P)

    print(sP[2])
コード例 #5
0
def sturm_method(poly, a, b):
    sturm_seq = sturm(poly)
    nums = []
    sign_changes = 0
    for el in sturm_seq:
        num = el.subs({x: a})
        nums.append(num)
    n = len(nums)
    na = 0
    for i in range(n - 1):
        if nums[i + 1] * nums[i] < 0:
            na += 1

    nums.clear()
    sign_changes = 0
    for el in sturm_seq:
        num = el.subs({x: b})
        nums.append(num)
    n = len(nums)
    nb = 0
    for i in range(n - 1):
        if nums[i + 1] * nums[i] < 0:
            nb += 1
    return na - nb
コード例 #6
0
def test_euclid_q():
    x = var('x')

    p = x**3 - 7*x + 7
    q = 3*x**2 - 7
    assert euclid_q(p, q, x)[-1] == -sturm(p)[-1]
コード例 #7
0
def test_euclid_q():
    x = var('x')

    p = x**3 - 7 * x + 7
    q = 3 * x**2 - 7
    assert euclid_q(p, q, x)[-1] == -sturm(p)[-1]