On Fri, Apr 3, 2009 at 8:41 AM, Colin Gillespie <[email protected]> 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.
Here is what I would do:
In [1]: p =Poly(2*x*y+y, x, y)
In [2]: p.as
p.as_base_exp p.as_independent p.as_primitive
p.as_basic p.as_integer p.as_real_imag
p.as_coeff_exponent p.as_leading_term p.as_reduced
p.as_coeff_factors p.as_monic p.as_squarefree
p.as_coeff_terms p.as_numer_denom p.as_uv_dict
p.as_coefficient p.as_poly p.assumptions0
p.as_dict p.as_powers_dict
In [2]: p.as_basic()
Out[2]: y + 2⋅x⋅y
In [3]: p.as_basic().subs({y: y+5, x: x+1})
Out[3]: 5 + y + 2⋅(1 + x)⋅(5 + y)
In [4]: Poly(p.as_basic().subs({y: y+5, x: x+1}))
---------------------------------------------------------------------------
SymbolsError Traceback (most recent call last)
/home/ondrej/repos/sympy/<ipython console> in <module>()
/home/ondrej/repos/sympy/sympy/polys/polynomial.pyc in __new__(cls,
poly, *symbols, **flags)
298 return poly
299 else:
--> 300 raise SymbolsError("No symbols were given")
301
302 stamp = frozenset(symbols)
SymbolsError: No symbols were given
In [5]: Poly(p.as_basic().subs({y: y+5, x: x+1}), x, y)
Out[5]: Poly(2*x*y + 10*x + 3*y + 15, x, y)
In [6]:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---