Substitution on Function Iteration

36 views
Skip to first unread message

Scott Guthery

unread,
Mar 24, 2015, 5:37:22 PM3/24/15
to sy...@googlegroups.com
Any insight into the following will be greatly appreciated.  Many thanks.

from sympy import *

x = symbols('x', integer=True)

def main(fns, q0):
    for fn in fns:
        print(fn)
        print(fn.subs([x,q0]))
    
if __name__ == '__main__':
    f1=x
    f2=x+2
    main([f1,f2], 3)

yields

x
Traceback (most recent call last):
  File ".../Subs.py", line 13, in <module>
    main([f1,f2], 3)
  File ".../Subs.py", line 8, in main
    print(fn.subs([x,q0]))
  File "C:\Python34\lib\site-packages\sympy\core\basic.py", line 842, in subs
    o, n = sequence[i]
TypeError: 'Symbol' object is not iterable

Sudhanshu Mishra

unread,
Mar 24, 2015, 5:44:47 PM3/24/15
to sy...@googlegroups.com
Hi Scott,

It looks like your subs call is wrong. It should be fn.subs(x, q0)

Hope this helps.

Sudhanshu Mishra

--
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/b96b9f35-cd77-449a-bcf4-99668181633e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Meurer

unread,
Mar 24, 2015, 8:02:51 PM3/24/15
to sy...@googlegroups.com
The argument to subs should either be subs(old, new), or an iterable
of (old, new) pairs, so subs(x, q0) or subs([(x, q0)]) (you can also
pass in a dictionary like subs({x: q0})).

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/CAFW_KCR2DpZKsWXuWJYW%3Dpwo1AsJf6sgCHbM0%3D%2BbfTMwF7bkLA%40mail.gmail.com.

Scott Guthery

unread,
Mar 24, 2015, 9:03:48 PM3/24/15
to sy...@googlegroups.com

Yep.  Thanks much, Sudhanshu
Cheers, Scott
Reply all
Reply to author
Forward
0 new messages