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, 21 Mar 2013 23:59:28 +0100- How to substitute a function within derivatives?https://ask.sagemath.org/question/9932/how-to-substitute-a-function-within-derivatives/I want to simplify an ODE by making a substitution, say g(x) -> h(x)*x, but can't get it to work. I tried:
g=function('g', x)
h=function('h', x)
dg = g.diff(x)
dg
sage output: D[0](g)(x)
dg.subs(g==h*x)
sage output: D[0](g)(x)
The substitution is not done for the g function within derivatives. I tried dg.subs(g(x)==h(x)*x) too, got deprecation warnings and the same results. How can I make this work? This is a simplified example, in reality, instead of dg, I have the lhs of an ODE defined interms of g(x).
Thanks
sgiaThu, 21 Mar 2013 23:59:28 +0100https://ask.sagemath.org/question/9932/
- Substitute formal function by an expression in a differential equationhttps://ask.sagemath.org/question/8293/substitute-formal-function-by-an-expression-in-a-differential-equation/This is a follow up to [substitute expression instead of formal function symbol](http://ask.sagemath.org/question/541/substitute-expression-instead-of-formal-function). I tried to no avail to apply the workaround proposed there for the following application where I build a differential equation involving a formal function P:
sage: x,y = var('x,y')
sage: P = function('P',x,y)
sage: z = var('z')
sage: C = function('C',z)
sage: equation = P(x=z,y=C) == 0
sage: dequation = diff(equation, z)
and then I would want to substitute P by a specific expression:
sage: Q(x,y) = y^2 - y + x
sage: dequation.substitute_function(P,Q)
But whatever I tried, I got:
D[0](C)(z)*D[1](P)(z, C(z)) + D[0](P)(z, C(z)) == 0
Is there a natural syntax to achieve this? If not, should this be a ticket?
Thanks!Nicolas M ThiĆ©ryThu, 25 Aug 2011 10:24:25 +0200https://ask.sagemath.org/question/8293/
- substitute expression instead of formal function symbolhttps://ask.sagemath.org/question/8110/substitute-expression-instead-of-formal-function-symbol/Hi, everyone.
The question seems to be basic, but I cannot find out any simple answer for it...
So, the case is as follows. Let's assume, we have some formal function symbol (which is intended later to be replaced by actual expression)
x = var('x'); f = function('f', x)
and some function, which uses 'f(x)' in its definition:
a, b = var('a b')
g(x) = a*f(x) + b*f(x)^2
now we would like to compute derivative of 'g(x)' (and possibly make some other manipulations)
h(x) = diff(g, x)
as a result we have h(x), which includes symbols like 'D[0]f(x)'. This can be answer for some problem in general form. But now we would like to evaluate this expression for particular 'f(x)' (and possibly multiple times with different expressinos), e. g. for 'f(x) = a*x + b'.
It is desirable to have this with something like
answer = h.subs({f:a*x + b}) # do not work :(
but this substitution do not work inside derivatives...
So, the question is: is there some simple solution (like simple subs() function) for the case I've described above? Or may be there is some standard tricks/patterns to solve this issue?
Thanks in advance for any suggestions.Dmitry SemikinWed, 11 May 2011 15:53:09 +0200https://ask.sagemath.org/question/8110/