Mathematical equation manipulation in Python

后端 未结 5 1251
天命终不由人
天命终不由人 2020-12-05 03:36

I want to develop a GUI application which displays a given mathematical equation. When you click upon a particular variable in the equation to signify that it is the unknown

5条回答
  •  我在风中等你
    2020-12-05 04:11

    Using SymPy, your example would go something like this:

    >>> import sympy
    >>> a,b,c,d,e = sympy.symbols('abcde')
    >>> r = (b+c*d)/e
    >>> l = a
    >>> r = sympy.solve(l-r,d)
    >>> l = d
    >>> r
    [(-b + a*e)/c]
    >>> 
    

    It seems to work for trigonometric functions too:

    >>> l = a
    >>> r = b*sympy.sin(c)
    >>> sympy.solve(l-r,c)
    [asin(a/b)]
    >>> 
    

    And since you are working with a GUI, you'll (probably) want to convert back and forth from strings to expressions:

    >>> r = '(b+c*d)/e'
    >>> sympy.sympify(r)
    (b + c*d)/e
    >>> sympy.sstr(_)
    '(b + c*d)/e'
    >>> 
    

    or you may prefer to display them as rendered LaTeX or MathML.

提交回复
热议问题