Exemplo n.º 1
0
def drawEquationTree(str0):
    flag = 0
    if '=' in str0:
        str0 = str0.replace(" ", '')
        if 'dy' in str0:
            str1 = str0.split('=')  #此时str1是一个具有两个元素的list
            str2 = str1[1]  #此时str2是一个字符串
            str3 = str2[1:]  #去掉开头的一个d
            total = trans(str3, flag=1)
            flag = 1
        else:
            str1 = str0.split('=')
            subleft = str1[0]
            subright = str1[1]

            subleft = trans(subleft, flag=1)
            subright = trans(subright, flag=1)
            total = subleft + '=' + subright
    else:
        total = trans(str0, flag=1)

    # total = total.replace("**",'^')  #这两句话以后可以不要
    root = Latex2tree(total)

    if flag:
        first = Node("\'")
        dNode = Node('d')
        first.right = root
        first.left = dNode
        root = first
    draw(root)
Exemplo n.º 2
0
def integra2(str0):
    # input: \int _ { 0 } ^ { \frac { \pi } { 2 } } \sin ( 4 x ) d x
    upstr = ''
    downstr = ''
    str0 = str0.replace(" ", "").replace('\int', '').replace('dx', '(1)')
    index1 = 1
    index2 = pairindex('{', index1, str0)
    index3 = index2 + 2
    index4 = pairindex('{', index3, str0)

    upstr = str0[index1 + 1:index2]
    downstr = str0[index3 + 1:index4]

    str0 = str0[index4 + 1:]

    str0 = trans(str0)
    upstr = trans(upstr)
    downstr = trans(downstr)

    x = Symbol('x')
    result = integrate(str0, (x, upstr, downstr))
    result1 = str(result)
    if 'x' in result1:
        result = result1.replace('**', '^')
    else:
        result = result.evalf()
    return result
Exemplo n.º 3
0
def latex2diff(str0):
    str0 = diffpreprocess(str0)
    str0 = trans(str0)
    result = diff(str0)
    result = str(result)
    afterprocess = diffprocess(result)
    return afterprocess
Exemplo n.º 4
0
def integra1(str0):
    str0 = str0.replace(" ", "").replace('\\int', '').replace('dx', '(1)')
    str0 = trans(str0)
    result = integrate(str0)
    result = str(result)
    result = result.replace('**', '^')
    return result
Exemplo n.º 5
0
def calculate(str0):
    str1 = trans(str0, flag=1)
    # print(str0)
    str2 = str2list(str1)  # 后面记得改一下str0
    # print(str2)
    str3 = InfixToPostfi(str2)
    # print(str3)
    result = postfixExpression(str3)
    return result
def equation_cluster(str0):
    str0 = str0.replace(' ', '')
    str0 = str0.replace('\\begin{cases}', '')
    str0 = str0.replace('\\end{cases}', '')
    strlist = str0.split('\\\\')

    strlist = [trans(a) for a in strlist]
    # strlist = [a.replace('\x0c', 'f') for a in strlist]

    s = solve(strlist)
    return s
    nx.draw_networkx(graph, pos, ax=ax, node_size=300, node_color='w', font_size=15)
    plt.show()

def Latex2tree(str0):
    str1 = str2list(str0)
    # print(str1)
    str2 = InfixToPostfi(str1)
    # print(str2)
    str3 = statistics(str2)
    # print(str3)
    tree = suffixExpr2Tree(str3)
    return tree

if __name__ == '__main__':
    str0 = '4 x'
    # strtest = '17.8+3.6-(3/10)*(7+3) -14'
    print(str0)
    str0 = trans(str0)
    str1 = str2list(str0)
    # print(str1)

    str2 = InfixToPostfi(str1)
    # print(str2)

    str3 = statistics(str2)
    # print(str3)

    root = suffixExpr2Tree(str3)

    draw(root)
Exemplo n.º 8
0
def calculate1(str0):
    str0 = trans(str0)
    result = N(str0)
    result = result.evalf()
    return result
def equation_Order2(str0):
    str0 = trans(str0)
    s = solve(str0)
    return s