Search code examples
symbolic-mathmaxima

Maxima CAS: how to substitute for the independent variable in derivative forms


I would like to change variable in a differential equation within Maxima, e.g.:

(%i1) diff(y(x),x);
                                   d
(%o1)                              -- (y(x))
                                   dx
(%i2) subst([x=a*z],%);
                                  d
(%o2)                            ---- (y(a z))
                                 da z

However I do not know how to proceed and get diff(y(a*z),z)/a. The Maxima manual mentions the question, but refers to the at command where this topic is not dealt with.


Solution

  • There are several methods for solve this task in maxima, let's use pdiff. first we solve two odes in maxima

    (%i1) eq:'diff(y,x) = -y;
                                       dy
    (%o1)                              -- = - y
                                       dx
    (%i2) ode2(eq, y, x);
                                              - x
    (%o2)                            y = %c %e
    (%i3) sol: ic1(%, x= 1, y= 8);
                                             1 - x
    (%o3)                            y = 8 %e
    

    maxima has no problem with complex ode like this:

    (%i4) eqcv : 'diff(y,x) = (x*y) / (3*x^2 - y^4);
                                    dy      x y
    (%o4)                           -- = ---------
                                    dx      2    4
                                         3 x  - y
    (%i5) ode2(eqcv, y, x);
                                       4    2
                                      y  - x
    (%o5)                           - ------- = %c
                                          6
                                       2 y
    (%i6) sol: ic1(%, x= 2, y= 1);
                                        4    2
                                       y  - x    3
    (%o6)                            - ------- = -
                                           6     2
                                        2 y
    

    but let's use variable changing on this equation using pdiff

    y = z ^ a

    (%i1) load(pdiff)$
    
    (%i5) eqcv : diff(y(x),x) = (x*y(x)) / (3*x^2 - y(x)^4);
    
                                             x y(x)
    (%o5)                       y   (x) = ------------
                                 (1)         2    4
                                          3 x  - y (x)
    
    (%i6) eqcv, y(x) := z(x)^a;
    
                                                     a
                               a - 1              x z (x)
    (%o6)                a z(x)      z   (x) = --------------
                                      (1)         2       4 a
                                               3 x  - z(x)
    

    then we can simplify:

    (%i7) % / z(x)^(a -1);
                                              x z(x)
    (%o7)                     a z   (x) = --------------
                                 (1)         2       4 a
                                          3 x  - z(x)
    (%i8) % / a;
                                             x z(x)
    (%o8)                    z   (x) = ------------------
                              (1)            2       4 a
                                       a (3 x  - z(x)   )
    

    and now we can apply a = 1/2

    (%i50) %, a = 1/2;
                                            2 x z(x)
    (%o50)                      z   (x) = ------------
                                 (1)         2    2
                                          3 x  - z (x)
    

    start to solve:

    (%i51) eq : %;
                                            2 x z(x)
    (%o51)                      z   (x) = ------------
                                 (1)         2    2
                                          3 x  - z (x)
    (%i52) eq;
                                            2 x z(x)
    (%o52)                      z   (x) = ------------
                                 (1)         2    2
                                          3 x  - z (x)
    
    
    (%i56) eq : convert_to_diff(eq);
                               d             2 x z(x)
    (%o56)                     -- (z(x)) = ------------
                               dx             2    2
                                           3 x  - z (x)
    
    (%i57) depends(z,x);
    (%o57)                              [z(x)]
    
    (%i58) eq : subst(z,z(x),eq);
                                    dz     2 x z
    (%o58)                          -- = ---------
                                    dx      2    2
                                         3 x  - z
    
    (%i59) ode2(eq,z,x);
    
                                       2    2
                                      z  - x
    (%o59)                          - ------- = %c
                                         3
                                        z
    

    you can also apply this to partial differential equations example from a mailing list:

    I am dealing with the following partial differential equation for the function T(r,t):

    diff( T, t ) - T^2 / r^2 * diff( ( r^2 * T^(sigma) * diff(T, r) + q / T ), r ) = 0

    I now want to introduce a new variable

    eta = r / t^(1/3)

    and a new function

    Psi(eta) = t^(1/3) * T^(1+sigma)

    and I would like Maxima to transform the partial differential equation for T(r,t) stated herebove into a differential equation for Psi(eta).

    solution:

    (%i1) load(pdiff)$
    (%i2) de : diff(f(x,y),x,2) + diff(f(x,y),y,2)$
    (%i3) de, f(x,y) := g(x/y);
    (%o3) g[(2)](x/y)/y^2+(2*x*g[(1)](x/y))/y^3+(x^2*g[(2)](x/y))/y^4
    (%i4) y^2 * %;
    (%o4) (g[(2)](x/y)/y^2+(2*x*g[(1)](x/y))/y^3+(x^2*g[(2)](x/y))/y^4)*y^2
    (%i5) ratsubst(w,x/y,%);
    (%o5) (w^2+1)*g[(2)](w)+2*w*g[(1)](w)
    (%i6) nde : convert_to_diff(%);
    (%o6) 2*w*('diff(g(w),w,1))+(w^2+1)*('diff(g(w),w,2))
    (%i7) depends(g,w)$
    (%i8) nde : subst(g,g(w),nde);
    (%o8) ('diff(g,w,2))*(w^2+1)+2*('diff(g,w,1))*w
    (%i9) ode2(nde,g,w);
    (%o9) g=%k1*atan(w)+%k2
    

    so in your case:

    (%i11) load(pdiff)$
    
    (%i12) eq : diff(y(x),x);
    (%o12)                              y   (x)
                                         (1)
    (%i13) eq, y(x) := t(a*x);
    (%o13)                            a t   (a x)
                                         (1)