Getting started with SymEval
SymEval allows you to define SymPy equations, then substitute Pint quantities (value + unit), and then shows you symbolically (LaTeX) how to arrive at the result.
Below some examples that start with the basics and progressively show more powerful SymEval funcionality and usecases.
Axial stress under a compressive force
Section titled “Axial stress under a compressive force”Define the equation for calculating the axial stress using SymPy:
Then define the values and units of the force acting on the structural member and its cross-sectional area:
Then substitute the inputs into the SymPy equation:
For convenience, it’s also possible to call sym_evalf as a method on a sympy.Equality. Moreover, there are a few keyword arguments (kwargs) to help you nicely format the LaTeX:
n_displayspecifies the significant figures shown in the LaTeX (defaults to 4).mode="verbose"adds an extra line showing all values converted to SI base units.
mode="one_line" collapses the equation, substituted quantities and result onto a single line:
quantity_evalf() on a DataFrame
Section titled “quantity_evalf() on a DataFrame”Now suppose you have done a structural analysis, which gave you the axial forces acting on the members (building columns and beams), and now you want to calculate what the resulting axial stresses on these members are. So, let’s:
- create a
polars.DataFramewith the forces and cross-sectional areas of these members; - calculate the axial stresses using
quantity_evalf()on theDataFrame; - symbolicly evaluate the axial stress in the member which we select from a
marimo.ui.tablewidget.
Axial Resistance of a Steel HSS Member
Section titled “Axial Resistance of a Steel HSS Member”as per CSA S16-17.
This is the example calculation that Connor Ferster, the author of handcalcs (huge inspiration for SymEval), shows in this “Engineering Calculations: Handcalcs-on-Jupyter vs. Excel” YouTube tutorial.
This example shows how you can define an entire table of inputs using marimo ui elements and then chain the result from one equation into the next.
Ideal Gas Law
Section titled “Ideal Gas Law”When solving the ideal gas law
you need to always know three out of four variables ( is the molar gas constant):
| Name | Symbol | SI-unit |
|---|---|---|
| Pressure | ||
| Volume | ||
| Temperature | ||
| Number of gas particles |
Now, given that SymEval is built on top of SymPy, SymEval will first symbolically rearrange the ideal gas law to isolate our unknown variable on the lefthand side with sympy.solve. After which the resulting expression feeds straight into sym_evalf.
The marimo ui elements combined with the piston widget are meant to give an explorable explanation of and some intuition for the ideal gas law.