Expression
Expression(parameter, expression)Numerical parametric expression object.
Args
- parameter (str | Sequence[str]): Independent variable name, or sequence of names.
- expression (str | tuple[str, str | float] | Sequence[str | tuple[str, str | float]]): Expression to be evaluated as a function of the parameter(s). A list of expressions can also be used.
When using multiple expressions, they are evaluated in sequence and
previous results are available to subsequent expressions by their name.
Expression names can be set by using tuples with (name, expression).
Examples
>>> e = pf.Expression("u", "2 * u")>>> e(1.5)3.0>>> e = pf.Expression("u", [("a", 2), ("b", "u^(a - 1)"), "a * b"])>>> e(3)array([2., 3., 6.])>>> e = pf.Expression(... ["x", "y"], ["sqrt(x^2 + y^2)", "atan2(y, x)"]... )>>> e(1, -1)array([ 1.41..., -0.78...])Note
Expression strings support the following:
- Constants:
e,pi - Operators:
+,-,*,/,%,^(exponent) - Functions:
abs,acos,and,asin,atan2,atan,ceil,cos,cosh,exp,floor,if,ln,log(same asln),log10,max,min,or,pow,sin,sinh,sqrt,tan,tanh
Functions max and min only accept 2 arguments.
Functions if, and, or are equivalent to the following
python expressions:
if(a, b, c) == b if a > 0 else cand(a, b) == b if a > 0 else aor(a, b) == a if a > 0 else b
Methods
Section titled “Methods”| Method | Description |
|---|---|
copy | Create a copy of this expression. |
copy(self)Create a copy of this expression.
Returns
New copy.
Attributes
Section titled “Attributes”| Attribute | Description |
|---|---|
expressions | list[tuple[str, str | float]]: Object expressions as a list (read only). |
parameters | list[str]: Object parameters as a list (read only). |
properties | Properties: Object properties. |
expressions
Section titled “expressions”list[tuple[str, str | float]]: Object expressions as a list (read only).
parameters
Section titled “parameters”list[str]: Object parameters as a list (read only).
properties
Section titled “properties”Properties: Object properties.