Sympy changes the order of display of coefficients in equations. In epidemiological models it is common practice to put parameters first followed by state variables. Sympy changes the order when it displays the system of equations (including when using sympy.printlatex()). Note, parameters are usually lower case and from the Greek, occasionally Latin, alphabets, whereas state variables are upper case and from the Latin alphabet.
Here is a code example:
import sympy
# Setup Symbols for Sympy
N, S, I, R, mu, beta, gamma = sympy.symbols('N S I R mu beta gamma')
# The system written to epidimiological mode format
ODE_S = mu*N-beta*S*I-mu*S
ODE_I = beta*S*I-(mu+gamma)*I
ODE_R = gamma*I-mu*R
ODEs = sympy.Matrix([ODE_S,ODE_I,ODE_R])
Yet the order changes when using:
ODEs
or
sympy.print_latex(ODEs)
So for instance, in the output the recovery term becomes $I \gamma $
, not what was input, $\gamma I$
. I would like this term to to remain $\gamma I$
, and a similar format for all other multiples.
I ask as this question as part of an issue with an epidimiological modelling package that uses sympy (see https://github.com/publichealthengland/pygom/issues/59). It would be handy if the order of input terms was preserved despite changes that might occur later to the equations.