Skip to content
Advertisement

Is it possible to assign a symbol of partial derivative via symbols() in SymPy?

I would like to symbolically represent one of variables as a partial derivative like:

dF_dx = symbols(‘dF/dx’)

so that display(dF_dx) would show it as:

enter image description here

Is there a way to do it? The official reference is not very clear to a newbie. Thank you.

Advertisement

Answer

_print_Derivative currently decides based on requires_partial if it’s going to use the rounded d symbol or not. The requires_partial function checks how many free symbols the expression is using, if it’s using more than one symbol then it will use the rounded d symbol, otherwise it will just use d instead.

To override this behaviour, we can just pass a custom LatexPrinter class to init_printing

JavaScript

OUTPUT:

enter image description here


See this post as well on how to use a custom latex printer.

All the code in this post is available in this repo.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement