ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 19 Dec 2019 20:18:18 +0100substitution of variable in the result of monomials()https://ask.sagemath.org/question/49089/substitution-of-variable-in-the-result-of-monomials/Given a polynomial in n variables, I'd like to extract the list of its monomials, and then manipulate that list by substituting certain variables for others.
Simple example: in $Z[x,y]$ consider the polynomial $1+x+y^2$; the list of its monomials (in some ordering) is $(1,x,y^2)$. My function should be able e.g. to take that list and substitute $y$ with $x$, namely return $[1,x,x^2]$.
At the moment, my code gives error, but I do not understand how to fix it.
N.<x1,x2> = PolynomialRing(ZZ, 2)
f = 1+x1+x2
g = f.monomials()
for i in range(3):
g[i] = g[i].substitute_expression(x2==x1)
Namely, how do I make a variable in the polynomial ring also have the substitute attribute? or is there a better way to achieve this?rue82Thu, 19 Dec 2019 20:18:18 +0100https://ask.sagemath.org/question/49089/Substitute variable in expressionhttps://ask.sagemath.org/question/25119/substitute-variable-in-expression/ Hello, I have to do a substitution in an expression: i want to substitute diff(psi) with omega, where i declared psi as psi =
function('psi',t)
I tried doing expr.substitute(diff(psi)==omega) but it doesn't work.
What do I have to do?
Thank you very much.SilviaThu, 04 Dec 2014 14:46:29 +0100https://ask.sagemath.org/question/25119/Substitution of a list of variableshttps://ask.sagemath.org/question/10606/substitution-of-a-list-of-variables/I wish substituting a list of variables, without having to substitute them 1 by 1.
Here is an example with an attempt which doesn't work :
sage: V=[var('x_%d' % i) for i in range(10)]; V
[x_0, x_1, x_2, x_3, x_4, x_5, x_6, x_7, x_8, x_9]
sage: S=[sum(V),prod(V)]; S
[x_0 + x_1 + x_2 + x_3 + x_4 + x_5 + x_6 + x_7 + x_8 + x_9,
x_0*x_1*x_2*x_3*x_4*x_5*x_6*x_7*x_8*x_9]
sage: for i in range(10):
....: S.subs(V[i]=i)
....:
File "<ipython-input-99-7670392e3358>", line 2
SyntaxError: keyword can't be an expression
How can we do this ?
Sébastien PalcouxSun, 13 Oct 2013 19:44:43 +0200https://ask.sagemath.org/question/10606/Change of variable in an integrationhttps://ask.sagemath.org/question/8679/change-of-variable-in-an-integration/How to indicate a change of variable to Sage in an integration when Sage seems clueless?Green diodSat, 28 Jan 2012 18:59:27 +0100https://ask.sagemath.org/question/8679/