Reputation: 754
I am testing https://zulko.wordpress.com/2012/04/15/symbolic-matrix-differentiation-with-sympy/ with Python35 and I got this error:
Traceback (most recent call last):
File "D:\Program Files\JetBrains\PyCharm 2016.1\helpers\pydev\pydev_run_in_console.py", line 71, in <module>
globals = run_file(file, None, None)
File "D:\Program Files\JetBrains\PyCharm 2016.1\helpers\pydev\pydev_run_in_console.py", line 31, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:\Program Files\JetBrains\PyCharm 2016.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/programs/python/wcf/test2/my.py", line 134, in <module>
matPrint( expand( expand( matDiff(H,X) ) ) )
File "D:/programs/python/wcf/test2/my.py", line 64, in matDiff
return MATRIX_DIFF_RULES[expr.__class__](expr,symbols)
File "D:/programs/python/wcf/test2/my.py", line 54, in <lambda>
Mul : lambda e,s : Mul(matDiff(e.args[0],s),Mul(*e.args[1:]))
File "D:/programs/python/wcf/test2/my.py", line 64, in matDiff
return MATRIX_DIFF_RULES[expr.__class__](expr,symbols)
File "D:/programs/python/wcf/test2/my.py", line 52, in <lambda>
Symbol : lambda e, s: d(e) if (e in s) else 0,
TypeError: argument of type 'Symbol' is not iterable
Upvotes: 2
Views: 852
Reputation: 91620
My guess is that the code was written against an old version of SymPy where you could write something like x in sin(x)
. Now, this is disallowed, and you have to use has
. So the replacement should be
Symbol : lambda e, s: d(e) if s.has(e) else 0,
Upvotes: 3