コード例 #1
0
def testRoots_4():
    f1 = MultiPower(np.array([[5,-1],[1,0]]))
    f2 = MultiPower(np.array([[1,-1],[-1,0]]))

    root = rf.roots([f1, f2])[0]

    assert(all(np.isclose(root, [-2,3])))
コード例 #2
0
def testRoots_7(): # This test sometimes fails due to stability issues...
    f1_coeff = np.zeros((3,3,3))
    f1_coeff[(0,2,0)] = 1
    f1_coeff[(1,1,0)] = -1
    f1_coeff[(1,0,1)] = -2
    f1 = MultiPower(f1_coeff)

    f2_coeff = np.zeros((4,4,4))
    f2_coeff[(0,3,0)] = 1
    f2_coeff[(0,0,2)] = 1
    f2_coeff[(0,0,0)] = 1
    f2 = MultiPower(f2_coeff)

    f3_coeff = np.zeros((3,3,3))
    f3_coeff[(2,1,1)] = 1
    f3_coeff[(0,1,1)] = -1
    f3 = MultiPower(f3_coeff)

    roots = rf.roots([f1, f2, f3])

    values_at_roots = [[f1.evaluate_at(root) for root in roots],
                   [f2.evaluate_at(root) for root in roots],
                   [f3.evaluate_at(root) for root in roots]]

    assert(np.all(np.isclose(values_at_roots, 0)))
コード例 #3
0
def testRoots_5():
    f1 = MultiPower(np.array([[0,-1],[0,0],[1,0]]))
    f2 = MultiPower(np.array([[1,-1],[1,0]]))

    roots = rf.roots([f1, f2])

    assert(all(np.isclose(roots[0], [-0.61803399,  0.38196601])))
    assert(all(np.isclose(roots[1], [1.61803399,  2.61803399])))
コード例 #4
0
def testRoots_3():
    # roots of [x^2-y, x^3-y+1]
    f1 = MultiPower(np.array([[0,-1],[0,0],[1,0]]))
    f2 = MultiPower(np.array([[1,-1],[0,0],[0,0],[1,0]]))

    roots = rf.roots([f1, f2])

    values_at_roots = np.array([[f1.evaluate_at(root) for root in roots],
                                [f2.evaluate_at(root) for root in roots]])

    assert(np.all(values_at_roots==0))
コード例 #5
0
def testRoots():
    f1 = MultiPower(np.array([[0,-1.5,.5],[-1.5,1.5,0],[1,0,0]]), clean_zeros=False)
    f2 = MultiPower(np.array([[0,0,0],[-1,0,1],[0,0,0]]), clean_zeros=False)
    f3 = MultiPower(np.array([[0,-1,0,1],[0,0,0,0],[0,0,0,0],[0,0,0,0]]), clean_zeros=False)

    roots = rf.roots([f1, f2, f3])
    values_at_roots = np.array([[f1.evaluate_at(root) for root in roots],
                    [f2.evaluate_at(root) for root in roots],
                    [f3.evaluate_at(root) for root in roots]])

    assert(np.all(values_at_roots==0))
コード例 #6
0
def testRoots_2():
    f1 = MultiPower(np.array([[[5,0,0],[0,0,0],[0,0,0]],
                          [[0,-2,0],[0,0,0],[0,0,0]],
                          [[1,0,0],[0,0,0],[0,0,0]]]))

    f2 = MultiPower(np.array([[[1,0,0],[0,1,0],[0,0,0]],
                          [[0,0,0],[0,0,0],[1,0,0]],
                          [[0,0,0],[0,0,0],[0,0,0]]]))

    f3 = MultiPower(np.array([[[0,0,0],[0,0,0],[3,0,0]],
                          [[0,-8,0],[0,0,0],[0,0,0]],
                          [[0,0,0],[0,0,0],[0,0,0]]]))

    roots = rf.roots([f1, f2, f3])

    values_at_roots = np.array([[f1.evaluate_at(root) for root in roots],
                    [f2.evaluate_at(root) for root in roots],
                    [f3.evaluate_at(root) for root in roots]])

    assert(np.all(abs(values_at_roots)<1.e-5))
コード例 #7
0
ファイル: test_in_steps.py プロジェクト: zachtylr21/Groebner
import numpy as np
import pandas as pd
from scipy.linalg import lu
import random
import time

#Local imports
from multi_cheb import MultiCheb
from multi_power import MultiPower
import maxheap
from groebner_class import Groebner
from convert_poly import cheb2poly, poly2cheb
import groebner_basis
from root_finder import roots

matrix1 = np.random.randint(-10,10,(2,3))
matrix2 = np.random.randint(-30,30,(3,3))
T1 = MultiCheb(matrix1)
T2 = MultiCheb(matrix2)
P1 = cheb2poly(T1)
P2 = cheb2poly(T2)

roots([P1,P2])
roots([T1,T2])
コード例 #8
0
def testRoots_6(): # test when ideal is not zero-dimensional
    f1 = MultiPower(np.array([[-12,-12],[1,1],[1,1]]))
    f2 = MultiPower(np.array([[6,3,-3],[-2,-1,1]]))

    roots = rf.roots([f1, f2])
    assert(roots == -1)