Skip to content Skip to sidebar Skip to footer

Mathematical Equations - Rendering And Evaluation With Python And Qt (and Sympy?)

I am developing a GUI application (in the civil engineering context) with python3 and QT and want to display an equation in three different ways: symbolic: sigma=N/A with values:

Solution 1:

commutative=False will only mark that one symbol as non-commutative. SymPy will put the commuting part (in this case, everything else) first, and follow it by the non-commuting symbols in the correct order.

But you shouldn't use that anyhow. It will not give you what you want (e.g., you'll get a*b**-1 instead of a/b if a and b are noncommutative, since a*b**-1 and b**-1*a are different).

I would recommend just getting the latex for the individual parts that you want, and piecing them together in the order you want using string formatting.

Alternately, you can write your own printer that orders things the way you want. See http://docs.sympy.org/latest/modules/printing.html if you are interested in taking that route, and you should also read the source code for the existing printer, since you'll probably want to just take what is already there and modify it a little. This method is good if you want to be more general, and the basic string concatenation gets too messy. If the example you showed is as complicated as it will get, it may be overkill, but if you need to support potentially arbitrarily complicated expressions, it may be better to do it this way.

If you decide to take that second route and need help writing a custom printer, feel free to ask here or on the SymPy mailing list.

Post a Comment for "Mathematical Equations - Rendering And Evaluation With Python And Qt (and Sympy?)"