Reputation: 11
I'm implementing a vector field method that should return a numeric value based on an (x, y) position, where x and y are both instances of pydrake.symbolic.Variable
. I'm essentially looking to run f(x, y) -> float inside of the dynamics method of my SymbolicVectorSystem
. Is it possible to evaluate the numeric value of x and y so that they can be used to compute f(x, y) numerically?
Upvotes: 1
Views: 122
Reputation: 5533
Yes. You can just call y = Evaluate(my_symbolic_expression)
, or y = Evaluate(my_vector_or_matrix_of_symbolic_expressions)
which are using https://drake.mit.edu/pydrake/pydrake.symbolic.html#pydrake.symbolic.Evaluate with the default arguments. This will return floats iff the expression is simply holding a constant value, or will throw an error if you still have symbols inside that need to be defined.
Upvotes: 1