Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To assign parameters to an expression tree generated from the text parsed by the function parse(), you can use variables to represent the unknown values in the parsed expression. For example, if the expression is "x + y", you can assign parameter values to x and y by creating variables for them and assigning values to those variables.

Here's an example code in Python:

from sympy import *
x, y = symbols('x y')
expression = parse_expr('x + y')
param_values = {x: 2, y: 3}
result = expression.subs(param_values)
print(result)

In this code, we first import the Symbol object from the sympy module and create symbols for x and y. Then we use the parse_expr() function to parse the expression "x + y". We create a dictionary of parameter values where x is assigned the value 2 and y is assigned the value 3.

Finally, we use the subs() method to substitute the parameter values into the expression and evaluate it. The result is then printed to the console.