Strange result - Bug in diff(F_tenson, b) ? (least squares - motive)

14 views
Skip to first unread message

Станислав Иванов

unread,
Aug 8, 2014, 2:46:17 PM8/8/14
to sy...@googlegroups.com
>>> from __future__ import division ... ... from sympy import * ... from sympy.tensor import IndexedBase, Idx ... ... a, b = symbols('a b') ... F_tensor = symbols('F_tensor', cls=Function)
... ... i = map(Idx, ['i']) ... ... x = IndexedBase('x') ... y = IndexedBase('y') ...
>>> F_tensor = (y[i] - (b*x[i]+a))**2
>>> F_tensor
(abx[i]+y[i])2
>>> diff(F_tensor, b)
2(abx[i]+y[i])2 x[i](abx[i]+y[i])1

Aaron Meurer

unread,
Aug 8, 2014, 3:23:01 PM8/8/14
to sy...@googlegroups.com
What's the result that you would expect? I get

In [31]: diff(F_tensor, b)
Out[31]: -2⋅(-a - b⋅x[i] + y[i])⋅x[i]

By the way, your code should just be i = Idx('i'). map returns a list in Python 2 and an iterator in Python 3. 

Aaron Meurer



--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
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/37834bb3-bae0-4678-9471-34b0afacca9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages