I want to take an expression and split it by symbols. For example
rate = symbols('0')
def add_rate(self, new_rate):
self.rate = self.rate + symbols(new_rate)
add_rate('-k\*A\*E')
So the whole thing is 0 + -k\\*A\\*E
. After that I want to change k
to 0.01
with method subs(symbol('k'), 0.01)
to be 0 + -0.01\\*A\\*E
and I can't cause whole expression -k\\*A\\*E
is the symbol.
Maybe do you know how to change k
to 0.01
?
Solusion is using the sympy.parsing.sympy_parser opportunities.
from sympy.parsing.sympy_parser import *
rate = symbols('0')
def add_rate(self, new_rate):
self.rate = self.rate + parse_expr(new_rate.rate_string)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.