Substitution on Function Iteration

36 visualizações
Pular para a primeira mensagem não lida

Scott Guthery

não lida,
24 de mar. de 2015, 17:37:2224/03/2015
para 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

não lida,
24 de mar. de 2015, 17:44:4724/03/2015
para 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

não lida,
24 de mar. de 2015, 20:02:5124/03/2015
para 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

não lida,
24 de mar. de 2015, 21:03:4824/03/2015
para sy...@googlegroups.com

Yep.  Thanks much, Sudhanshu
Cheers, Scott
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem