# Revision history [back]

### 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: D0(x)

dg.subs(g==h*x)

sage output: D0(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

 2 No.2 Revision ppurka 2111 ●17 ●38

### 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)
dgdg
sage output: D0(x)D[0](g)(x)
dg.subs(g==h*x)
dg.subs(g==h*x) sage output: D0(x)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

 3 retagged FrédéricC 4189 ●3 ●37 ●85

### 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