Tip
An interactive online version of this notebook is available, which can be
accessed via
Alternatively, you may download this notebook and run it offline.
Using latexify in PyBaMM#
In this notebook we show how to use latexify
to print all the model equations.
First we import pybamm
[1]:
%pip install "pybamm[plot,cite]" -q # install PyBaMM if it is not installed
import pybamm
ERROR: Invalid requirement: '#'
Note: you may need to restart the kernel to use updated packages.
Then we load a model
[2]:
model = pybamm.lithium_ion.SPM()
Now that we have defined a model we can use latexify to get the latex of all the model equations
[3]:
model.latexify()
[3]:
We can also get a list of all the equations instead of a single line joined by newline
[4]:
model.latexify(newline=False)
[4]:
latexify can also be used to get the equations in a file format like png, jpg, pdf or tex.
[5]:
model.latexify("spm_equations_.png")
will create a png file titled spm_equations.png
in the working directory.
[6]:
model_spme = pybamm.lithium_ion.SPMe()
Jupyter notebook sometimes cannot render latex output that is too large. In that case we use newline=False
and loop over the lines. When newline=False
it returns a list, so it inherits all the properties of a list and you can also do something like this
[7]:
spme_latex = model_spme.latexify(newline=False)
for line in spme_latex:
display(line)
References#
The relevant papers for this notebook are:
[8]:
pybamm.print_citations()
[1] Von DAG Bruggeman. Berechnung verschiedener physikalischer konstanten von heterogenen substanzen. i. dielektrizitätskonstanten und leitfähigkeiten der mischkörper aus isotropen substanzen. Annalen der physik, 416(7):636–664, 1935.
[2] Charles R. Harris, K. Jarrod Millman, Stéfan J. van der Walt, Ralf Gommers, Pauli Virtanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith, and others. Array programming with NumPy. Nature, 585(7825):357–362, 2020. doi:10.1038/s41586-020-2649-2.
[3] Scott G. Marquis, Valentin Sulzer, Robert Timms, Colin P. Please, and S. Jon Chapman. An asymptotic derivation of a single particle model with electrolyte. Journal of The Electrochemical Society, 166(15):A3693–A3706, 2019. doi:10.1149/2.0341915jes.
[4] Valentin Sulzer, Scott G. Marquis, Robert Timms, Martin Robinson, and S. Jon Chapman. Python Battery Mathematical Modelling (PyBaMM). Journal of Open Research Software, 9(1):14, 2021. doi:10.5334/jors.309.