ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 29 Jun 2017 16:12:29 -0500Substitute expression for function in differential equationhttp://ask.sagemath.org/question/38130/substitute-expression-for-function-in-differential-equation/ This is related to [8293](https://ask.sagemath.org/question/8293/substitute-formal-function-by-an-expression-in-a-differential-equation/), but a lot has changed since then, so I wonder if there is a way to achieve this now.
Expanding on an example from [26114](https://ask.sagemath.org/question/26114/why-is-basic-arithmetic-disallowed-on-symbolic-functions/), I define a differential equation based on unevaluated functions and then want to substitute one of the functions (H) by an expression (T_s^2):
sage: var('T_s')
sage: B = function('B')(T_s)
sage: E = function('E')(T_s)
sage: H = function('H')(T_s)
sage: eq_B_TS = B == H/E
sage: eq1 = diff(eq_B_TS, T_s)
sage: eq1
diff(B(T_s), T_s) == -H(T_s)*diff(E(T_s), T_s)/E(T_s)^2 + diff(H(T_s), T_s)/E(T_s)
sage: eq1.subs(H == T_s^2)
diff(B(T_s), T_s) == -T_s^2*diff(E(T_s), T_s)/E(T_s)^2 + diff(H(T_s), T_s)/E(T_s)
I expected this output:
diff(B(T_s), T_s) == -T_s^2*diff(E(T_s), T_s)/E(T_s)^2 + 2*T_s/E(T_s)
However, the substitution was not carried out inside the differential. Is this a missing feature or a bug? Basically, I would like to be able to formulate general symbolic equations including differentials and integrals, and then insert explicit expressions for the different elements that would allow evaluation of the differentials and integrals. stanThu, 29 Jun 2017 16:12:29 -0500http://ask.sagemath.org/question/38130/Substitution of several variableshttp://ask.sagemath.org/question/32720/substitution-of-several-variables/
Let $f=f(x_1(t),x_2(t))$ be defined as follows:
sage: var('t mu')
sage: x=list()
sage: x.append( function('x1')(t) )
sage: x.append( function('x2')(t) )
sage: f = x[0] - mu*x[0]^2*x[1]
sage: f
$f = x_1(t) - \mu x_1(t)^2 x_2(t)$.
Now, I need to to substitute the term containing $x_1^2(t) x_2(t)$ in $f$ by some new auxiliary variable $x_3(t)$, that is, to obtain $f = x_1(t) - \mu x_3(t) $. However, this code doesn't work:
sage: x.append( function('x3')(t) )
sage: f.subs({x[0]^2*x[1] : x[2]})
Some ideas? Thanks.
This code is motivated by symbolic manipulation with ODEs (think of $f$ as being the right-hand side term in the autonomous ODE system $\dot{x}(t) = f(x(t))$ ).mforetsSat, 05 Mar 2016 05:36:51 -0600http://ask.sagemath.org/question/32720/