Thanks Ondrej, >I strongly suggest not to use this string syntax
I am sorry, but I want to get the derivatives of general equation including some functions, exp, sin/cos/tan, and pow and so on. It is given by a string variable. import sympy x = sympy.symbols('x') f = pow(x,2) g = sympy.diff(f,x) print g This gives 2*x and is correct, but f = pow(x,2) seems questionable. You said "no "pow" function in sympy", but g1= sympy.diff(pow(x,2),x) gives correct result 2*x. Why ? Pow function is critical for me because my mathml converter gives pow functions even if simple x**2 is converted to pow(x,2). czbebe On 12月8日, 午前11:25, Ondrej Certik <ond...@certik.cz> wrote: > On Mon, Dec 7, 2009 at 5:57 PM, czbebe <o...@bpe.es.osaka-u.ac.jp> wrote: > > Hi, > > > Following porblem I met. > > > import sympy > > x = sympy.symbols('x') > > f = 'pow(x,2)' > > g = sympy.diff(f,x) > > print g > > g1= sympy.diff(pow(x,2),x) > > print g1 > > > g outputs D(pow(x, 2), x) > > g1 is 2*x > > > g1 is all right, but g is wrong. > > > if f='sin(x)', g =con(x) and it is correct. > > > Why f = 'pow(x,2)' can't give correct answer ? > > That's because there is no "pow" function in sympy, so sympify just > creates an unknown function "pow" for you: > > In [1]: p = sympify("pow(x, 2)") > > In [2]: p > Out[2]: pow(x, 2) > > In [3]: p.diff(x) > Out[3]: > d > ──(pow(x, 2)) > dx > > it's the same as using any other name, like this: > > In [4]: p = sympify("powx(x, 2)") > > In [5]: p > Out[5]: powx(x, 2) > > What you want to use is "Pow", then it works. > > That being said, I strongly suggest not to use this string syntax at > all (if there is some other way to do that), as you can see, it easily > leads to confusion. > > Ondrej- 引用テキストを表示しない - > > - 引用テキストを表示 - -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.