-
Notifications
You must be signed in to change notification settings - Fork 6
Equation Syntax in PyPLANE
PyPLANE relies on the SymPy library for processing the equation strings input into the PyPLANE interface. Early on in the development of PyPLANE the decision was made to enforce explicit operator expression in the equation strings, due to confusing/conflicting formulations as SoEs get more complex.
As such, we've written up a short guide for writing equations in PyPLANE.
It is worth mentioning the variables and parameters that can be referenced in the equation strings.
Firstly, note that PyPLANE can be used to analyse both one- and two-dimensional SoEs; the number of dimensions in the system affects the independent and dependent variables "available" for reference.
For both one- and two-dimensional systems, the independent variable is time, denoted t. Thus all numerical integrations occur over a range of time. For one-dimensional systems, there is obviously only one dependent variable; this variable is denoted as x or, more explicitly, x(t). Now, the point of numerically solving an ODE is to find a solution to x(t) for a given derivative of x (denoted x') and initial/boundary condition. Thus, it is x' that is being expressed by the user on the PyPLANE GUI; x' may or may not be a function of t.
The independent variable remains the same for two-dimensional systems. The only difference is that there is now two dependent variables to evaluate: x(t) and y(t). Thus, the user describes x' and y' on the PyPLANE GUI.
To summarise:
- One-dimensional systems
- Independent variable:
t - Dependent variable:
x
- Independent variable:
- Two-dimensional systems
- Independent variable:
t - Dependent variables:
xandy
- Independent variable:
The user also has the ability to define constant values which can be referred to in the equation strings. Currently PyPLANE supports up to five constants at any one time. Any constants defined in the parameter entry boxes with a label and corresponding value can be referenced in the DE expressions.
The mathematical syntax used in PyPLANE is of the standard explicit variety:
- Addition: +
- Subtraction: -
- Multiplication: *
- Division: /
- Exponentiation: ^ (or **)
The usual order of operations is followed (remember BEMDAS).
The reason for the switch to explicit over implicit mathematical notation is a simple one. Consider a simple example. The user may define x' as asin(bt) in the case of implicit notation. In this example, SymPy gets confused and cannot figure out whether x' is a*sin(b*t) or the arcsine (a.k.a. the inverse sine) of b*t, which is denoted asin by Python. An observant reader may suggest, for example, "Just change the parameter labels so that there is no naming conflict" or "Just use more brackets". It was decided, however, that for complex equations it is better to err on the side of caution and enforce explicit notation.
SymPy (and therefore PyPLANE) recognises most common functions a user may wish to reference. Some examples include:
- Trigonometric functions: sin, cos, tan, sinh, cosh, csc, etc.
- Inverse trigonometric functions: asin, acos, atan, asinh, acosh, acsc, etc.
- Logarithms: log and exp
For an exhaustive list see the SymPy docs: https://docs.sympy.org/latest/modules/functions/index.html
For more detailed instructions and guidance, visit the SymPy docs: https://docs.sympy.org/latest/index.html