コード例 #1
0
ファイル: mypoly.py プロジェクト: nbliss/puiseux
    def __init__(self,poly,checkReduced=True):
        """
        2x^2-3x+1 would be input as [[2,2],[-3,1],[1,0]]
        and represented internally as {2:2,1:-3,0:1} i.e. the keys
        are the exponents and the values are the coefficients
        --OR-- can be input as a dictionary, in which case it will
        just be copied to internal

        Coefficients can be complex, int, long (if you really want to),
        or (in the most usefull case) puiseux polynomials (using the
        puiseuxPoly class).

        **Maybe not**: they might need to be Puiseux objects?

        checkReduced is a flag that determines if when setting
        up the internal representation we check for like terms.
        Be careful with it!!! If poly is a dict, checkReduced doesn't
        matter since it can't have repeated keys (exponents)
        """
        self.internal = {}
        if type(poly)==str:
            """
            This is bad. Uses eval.
            """
            from sympy import poly as symp
            from sympy.abc import x,y
            s = poly
            s = s.replace('^','**')
            p = symp(eval(s),x,y,domain='CC')
            print p
            d = {item[0][1]:puiseux({item[0][0]:complex(item[1])}) for item in p.terms()}
            for item in p.terms():
                if item[0][1] in d.keys():
                    d[item[0][1]]+=puiseux({item[0][0]:complex(item[1])})
                else: d[item[0][1]] = puiseux({item[0][0]:complex(item[1])})
            poly = d
        if type(poly)==dict:
            for key in poly.keys():
                if type(poly[key])!=puiseux:
                    self.internal[key] = puiseux({0:poly[key]})
                else: self.internal[key] = poly[key]
        elif checkReduced:
            self.internal = {poly[0][1]:poly[0][0]}
            for mon in poly[1:]:
                coeff = mon[0]
                exponent = mon[1]
                if exponent in self.internal:
                    self.internal[exponent] += coeff
                else: self.internal[exponent] = coeff
        else:
            self.internal = {}
            for elt in poly:
                self.internal[elt[1]]=elt[0]
        for key in self.internal.keys():
            if self.internal[key]==0:
                self.internal.pop(key)
        if self.internal=={}:self.internal = {0:0}
コード例 #2
0
def test_Milieu():
    A = Point(1, 2)
    B = Point(2, 4)
    I = Milieu(A, B)
    assert (I.x == (A.x + B.x) / 2 and I.y == (A.y + B.y) / 2)
    assertEqual(type(I.coordonnees), tuple)
    C = Point('1/3', '1')
    D = Point('1', '1')
    J = Milieu(C, D)
    assert (J.x == symp('2/3'))
コード例 #3
0
ファイル: test_points.py プロジェクト: TeddyBoomer/geophar
def test_Milieu():
    A = Point(1,2)
    B = Point(2,4)
    I = Milieu(A,B)
    assert(I.x == (A.x+B.x)/2 and I.y == (A.y+B.y)/2)
    assertEqual(type(I.coordonnees),  tuple)
    C = Point('1/3', '1')
    D = Point('1', '1')
    J = Milieu(C, D)
    assert(J.x == symp('2/3'))
コード例 #4
0
def test_Point_sympy():
    A = Point('1/2', '2/3')
    assertEqual(A.x, symp('1/2'))
    assertAlmostEqual(A.coordonnees, (1 / 2, 2 / 3))
コード例 #5
0
ファイル: test_points.py プロジェクト: TeddyBoomer/geophar
def test_Point_sympy():
    A = Point('1/2', '2/3')
    assertEqual(A.x, symp('1/2'))
    assertAlmostEqual(A.coordonnees, (1/2, 2/3))
コード例 #6
0
csl = coordinate_system_link


def convert_point_forward(p0):
    x0_, y0_, z0_ = p0
    x1_ = csl['x1'].subs(x0, x0_).subs(y0, y0_).subs(z0, z0_)
    y1_ = csl['y1'].subs(x0, x0_).subs(y0, y0_).subs(z0, z0_)
    z1_ = csl['z1'].subs(x0, x0_).subs(y0, y0_).subs(z0, z0_)
    return x1_, y1_, z1_


# The points at which we'll convert representations
A0 = (1, 1, 1)
B0 = (0, 0, 2)
C0 = (symp(1) / 2, 10, -10)

A1 = convert_point_forward(A0)
B1 = convert_point_forward(B0)
C1 = convert_point_forward(C0)

# The tensors to represent in the new coordinate system

# vectors:
v0 = Matrix([1, 1, 1])
w0 = Matrix([0, 0, 1])
s0 = Matrix([symp(1) / 2, 3, sqrt(2)])

# covectors:
α0 = Matrix([1, 4, symp(1) / 2]).transpose()
β0 = Matrix([1, 1, 1]).transpose()
コード例 #7
0
def convert_point_backward(p1):
    r_, φ_, θ_ = p1
    x_ = symp(csl['x'].subs(r, r_).subs(φ, φ_).subs(θ, θ_))
    y_ = symp(csl['y'].subs(r, r_).subs(φ, φ_).subs(θ, θ_))
    z_ = symp(csl['z'].subs(r, r_).subs(φ, φ_).subs(θ, θ_))
    return x_, y_, z_
コード例 #8
0
def convert_point_forward(p0):
    x_, y_, z_ = p0
    r_ = symp(csl['r'].subs(x, x_).subs(y, y_).subs(z, z_))
    φ_ = symp(csl['φ'].subs(x, x_).subs(y, y_).subs(z, z_))
    θ_ = symp(csl['θ'].subs(x, x_).subs(y, y_).subs(z, z_))
    return r_, φ_, θ_
コード例 #9
0
C1 = convert_point_forward(C0)
D1 = convert_point_forward(D0)

E0 = convert_point_backward(E1)
F0 = convert_point_backward(F1)

# The tensors to represent in the new coordinate system

# vectors:
v0 = Matrix([1, 1, 1])
w0 = Matrix([0, 0, 1])
s1 = Matrix([1, 0, 0])
t1 = Matrix([0, 0, 1])

# covectors:
α0 = Matrix([1, 4, symp(1) / 2]).transpose()
β0 = Matrix([1, 1, 1]).transpose()

# linear maps:
L0 = Matrix([[9, 2, 3], [8, 1, 4], [7, 6, 5]])

# the metric tensor
g0 = sp.eye(3)

# The jacobian matrices, JF is the forward jacobian and JB is the inverse jacobian

JF = Matrix([
    [diff(csl['x'], r),
     diff(csl['x'], φ),
     diff(csl['x'], θ)],
    [diff(csl['y'], r),