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)
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)
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)
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])
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
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]
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]