Perfect.

Thanks

Colin
> On Fri, Apr 03, 2009 at 08:41:05AM -0700, Colin Gillespie wrote:
>
> > Dear All,
>
> > Quick question. I have a polynomial:
>
> > p =Poly(2*x*y+y, x, y)
>
> > and I want to substitute in y = y+5 and x= x+1 How would I do this?
>
> > I've tried things like:
>
> > p.subs((y, y+5), (x, x+1))
>
> > but this doesn't work.
>
> > Cheers
>
> > Colin
>
> you should refer to Basic.subs() docstring:
>
> In [1]: p = Poly(2*x*y+y, x, y)
>
> In [2]: p.subs?
> Type:           instancemethod
> Base Class:     <type 'instancemethod'>
> String Form:    <bound method Poly.subs of Poly(2*x*y + y, x, y)>
> Namespace:      Interactive
> File:           /home/matt/repo/git/sympy/sympy/core/basic.py
> Definition:     p.subs(self, *args)
> Docstring:
>     Substitutes an expression.
>
>     Calls either _subs_old_new, _subs_dict or _subs_list depending
>     if you give it two arguments (old, new), a dictionary or a list.
>
>     Examples:
>
>     >>> from sympy import *
>     >>> x,y = symbols('xy')
>     >>> (1+x*y).subs(x, pi)
>     1 + pi*y
>     >>> (1+x*y).subs({x:pi, y:2})
>     1 + 2*pi
>     >>> (1+x*y).subs([(x,pi), (y,2)])
>     1 + 2*pi
>
> In [3]: p.subs({y:y+5,x:x+1})
> Out[3]: Poly(2*x*y + 10*x + 3*y + 15, x, y)
>
> In [4]: p.subs([(y, y+5), (x, x+1)])
> Out[4]: Poly(2*x*y + 10*x + 3*y + 15, x, y)
>
> In [5]: p.as_basic().subs({y:y+5,x:x+1})
> Out[5]: 5 + y + 2⋅(1 + x)⋅(5 + y)
>
> In [6]: expand(_) == _4.as_basic()
> Out[6]: True
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to