On Wed, Nov 18, 2020 at 5:37 PM Oscar <[email protected]> wrote: > > Hi David, > > It's not completely intuitive but you can do the substitution in several > stages. In your example (this is run isympy where f and g are both functions): > > In [24]: eq = Eq(n**2*f(x) - x*Derivative(f(x), x) + (1 - > 2*x)*Derivative(f(x), (x, 2)), 0) > > In [25]: eq > Out[25]: > 2 > 2 d d > n ⋅f(x) - x⋅──(f(x)) + (1 - 2⋅x)⋅───(f(x)) = 0 > dx 2 > dx > > In [26]: eq.subs(f(x), g(cos(t))) > Out[26]: > 2 > 2 d d > n ⋅g(cos(t)) - x⋅──(g(cos(t))) + (1 - 2⋅x)⋅───(g(cos(t))) = 0 > dx 2 > dx > > In [27]: eq.subs(f(x), g(cos(t))).doit() > Out[27]: > 2 > n ⋅g(cos(t)) = 0
Isn't this wrong? You are replacing f(x) with an expression that does not depend on x, then evaluating the derivatives that are still in terms of x, so they go to 0. > > More substitutions are probably needed to continue from here. > > Ideally sympy would have a function like maple's dchange: > https://www.maplesoft.com/support/help/Maple/view.aspx?path=PDEtools/dchange > https://github.com/sympy/sympy/issues/17590 I wonder if we need a separate function or if subs() itself should just do this. OTOH that might break existing code, since currently subs works like >>> diff(f(x), x).subs(f(x), y) Derivative(y, x) which is intended behavior since it allows using subs iteratively to do changes of variables, or things like cse(). Aaron Meurer > > Oscar > On Thursday, 19 November 2020 at 00:08:01 UTC [email protected] wrote: >> >> Dear Group, >> >> Suppose I have a differential equation such as: >> >> Eq(n^2*f(x) - x*Derivative(f(x), x) + (1 - 2*x)*Derivative(f(x), (x, 2))) >> >> (Though typically more complicated) >> >> and I want to replace the x variable - say x=cos(t) >> >> Is there a way to make that substitution within SymPy and get back a >> differential equation in t, as opposed to simply throwing the equation to >> dsolve and hoping that it will solve it? >> >> Likewise, is it possible to make a change of variable within an integral >> without simply letting integrate loose on it? >> >> David >> >> >> > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/07b2ec37-30b8-4a6f-8690-c05bfe958ce0n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6K8ZLUq9T-mqLWeSpmO2PG%3D%2B_8Kt1rkvHRD87DvqCf%2Bhw%40mail.gmail.com.
