Expression¶
- class photonforge.Expression(parameter, expresssion)¶
Numerical parametric expression object.
- Parameters:
parameter – Independent variable name, or sequence of names.
expression – 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 = Expression("u", "2 * u") >>> e(1.5) 3.0 >>> e = Expression("u", [("a", 2), ("b", "u^(a - 1)"), "a * b"]) >>> e(3) array([2., 3., 6.]) >>> e = Expression(["x", "y"], ["sqrt(x^2 + y^2)", "atan2(y, x)"]) >>> e(1, -1) array([ 1.41421356, -0.78539816])
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
andmin
only accept 2 arguments.Functions
if
,and
,or
are equivalent to the following python expressions:if(a, b, c) == b if a > 0 else c
and(a, b) == b if a > 0 else a
or(a, b) == a if a > 0 else b
Methods
copy
()Create a copy of this expression.
Attributes
Object expressions as a list.
Object parameters as a list.
- copy()¶
Create a copy of this expression.
- Returns:
New copy.
- expressions¶
Object expressions as a list.
- parameters¶
Object parameters as a list.