Can I use parse_expr to parse an expression such as 
"a1*x1**2+a2*x1+a3+a4*x1*x2+a5*x2**2" and inject the symbols into globals 
or locals namespace? 

Looks like auto_symbol is not doing this. So I have to manually inject each 
symbol using sympy.var() method.

exp0=parse_expr("a1*x1**2+a2*x1+a3+a4*x1*x2+a5*x2**2",transformations=(auto_number,auto_symbol))
exp0.subs(a1,10)


---------------------------------------------------------------------------NameError
                                 Traceback (most recent call 
last)<ipython-input-4-19dc46bbe490> in <module>()----> 1 exp0.subs(a1,10)
NameError: name 'a1' is not defined



But after my hack:

for each_sym in exp0.atoms(sympy.Symbol):
    sympy.var(each_sym.__str__())


exp0.subs(a1,10)

2*x1 + a3 + a4*x1*x2 + a5*x2**2 + 10*x1**2

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/26d01fa4-15fd-45da-b043-9197410f0286%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to